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

peb iterator #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

peb iterator #34

wants to merge 2 commits into from

Conversation

frairon
Copy link
Contributor

@frairon frairon commented May 31, 2024

  • delete telly
  • implement disktail

return nil, fmt.Errorf("error opening storage %s: %w", path, err)
}

ring := &DiskTail[T]{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldnt call the tailer ring :)

).ErrorOrNil()
}

// Run starts the ring. It's only allowed to be called once per instance.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ring

itemHandler := handler

if skipDuplicates {
keys := make(map[string]struct{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This map could grow really big, but our main use case is iterating over a couple thousand users with a key size of 24, so this should not be a problem.

time.Sleep(100 * time.Millisecond)
}
t.Fatalf("operation timed out")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would also add a test for the cleaner

Comment on lines +166 to +175
storedOffsets, err := r.getOffsets(parts)
if err != nil {
return fmt.Errorf("error reading local offsets: %w", err)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be moved above errgroup.WithContext(ctx)

}

type IterStats struct {
sync.Mutex

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Mutex is public, but it shouldn't.
A caller of (r *DiskTail[T]) Iterate could pass already locked IterStats, deadlocking the whole thing.

Comment on lines +333 to +342
itemsIterated int64
// number of unique keys. Note that this value will be 0 if duplicates are included when
// iterating.
uniqueKeys int64

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use atomic.Int64 ? It's there since 1.19.

// track oldest timestamp for stats
timestamp, _, _ := decodeKey(key)
if stats.oldestItem.IsZero() || timestamp.Before(stats.oldestItem) {
stats.oldestItem = timestamp

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The read (func (is *IterStats) OldestItem() time.Time) is protected by the lock.
But the write isn't?


func (r *DiskTail[T]) Iterate(ctx context.Context, skipDuplicates bool, stats *IterStats, handler func(item *Item[T]) HandleResult) error {
if stats == nil {
stats = &IterStats{}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locking on these stats doesn't make much sense? They're not visible to the caller.

// skip it
return Continue
}
keys[item.Key] = struct{}{}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map is not protected by the lock?
Is there a difference between uniqueKeys and map regarding access?

}
}

for {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for {
for ctx.Err() == nil {

and remove the condition below

Comment on lines 420 to 469
if !it.Prev() {
return nil
} else {
continue
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the negation and swap then & else.
Fits the skip it comment better IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants