8000 Refactor handling submits batch to avoid stuck submits by poszu · Pull Request #403 · spacemeshos/poet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor handling submits 8000 batch to avoid stuck submits #403

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

Merged
merged 1 commit into from
Sep 20, 2023
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
14 changes: 6 additions & 8 deletions registration/round.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func newRound(epoch uint, dbdir string, options ...newRoundOptionFunc) (*round,
maxBatchSize: opts.maxSubmitBatchSize,
flushInterval: opts.submitFlushInterval,
pendingSubmits: make(map[string]pendingSubmit),
batch: leveldb.MakeBatch(opts.maxSubmitBatchSize),
}

membersCounter.Add(float64(r.members))
Expand Down Expand Up @@ -159,1 BCB1 5 +160,9 @@ func (r *round) submit(ctx context.Context, key, challenge []byte) (<-chan error
}
}

if r.batch == nil {
r.batch = leveldb.MakeBatch(r.maxBatchSize)
time.AfterFunc(r.flushInterval, r.flushPendingSubmits)
}

registered, err := r.db.Get(key, nil)
switch {
case errors.Is(err, leveldb.ErrNotFound):

// OK - challenge is not registered yet.
case err != nil:
return nil, fmt.Errorf("failed to check if challenge is registered: %w", err)
Expand All @@ -186,6 +181,9 @@ func (r *round) submit(ctx context.Context, key, challenge []byte) (<-chan error

if r.batch.Len() >= r.maxBatchSize {
r.flushPendingSubmitsLocked()
} else if r.batch.Len() == 1 {
logging.FromContext(ctx).Debug("scheduling flush of pending submits", zap.Uint("round", r.epoch), zap.Duration("interval", r.flushInterval))
time.AfterFunc(r.flushInterval, r.flushPendingSubmits)
}

return done, nil
Expand All @@ -198,7 +196,7 @@ func (r *round) flushPendingSubmits() {
}

func (r *round) flushPendingSubmitsLocked() {
if r.batch == nil || r.batch.Len() == 0 {
if r.batch.Len() == 0 {
return
}
logging.FromContext(context.Background()).
Expand All @@ -216,7 +214,7 @@ func (r *round) flushPendingSubmitsLocked() {
r.membersCounter.Add(float64(len(r.pendingSubmits)))

clear(r.pendingSubmits)
r.batch = nil
r.batch.Reset()
}

func countMembersInDB(db *leveldb.DB) (count int) {
Expand Down
0