mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
seaweed-block: fold writeBudgetErrorFreed into writeBudgetError
writeBudgetError takes the freed-space look as a parameter instead of keeping a second name for it; callers without a WAL sample pass nil. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
50c6d2d699
commit
f47f3593d8
3 files changed
+14
-18
No files matched your search
@@ -32,7 +32,7 @@ func (s *WALStore) lockFastWALAppend(ctx context.Context, deadline time.Time, bl
|
||||
if s.closed {
|
||||
return false, errVolumeClosed
|
||||
}
|
||||
if err := s.writeBudgetError(ctx, deadline); err != nil {
|
||||
if err := s.writeBudgetError(ctx, deadline, nil); err != nil {
|
||||
return false, err
|
||||
}
|
||||
w := s.v3.w
|
||||
|
||||
@@ -544,7 +544,7 @@ func (s *WALStore) WriteContext(ctx context.Context, lba uint32, data []byte) (u
|
||||
}
|
||||
defer s.lifecycleMu.RUnlock()
|
||||
|
||||
if err := s.writeBudgetError(ctx, deadline); err != nil {
|
||||
if err := s.writeBudgetError(ctx, deadline, nil); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
fastLocked, err := s.lockFastWALAppend(ctx, deadline, 1)
|
||||
@@ -583,7 +583,7 @@ func (s *WALStore) WriteContext(ctx context.Context, lba uint32, data []byte) (u
|
||||
s.mu.Unlock()
|
||||
return 0, err
|
||||
}
|
||||
if err := s.writeBudgetError(ctx, deadline); err != nil {
|
||||
if err := s.writeBudgetError(ctx, deadline, nil); err != nil {
|
||||
s.mu.Unlock()
|
||||
return 0, err
|
||||
}
|
||||
@@ -592,7 +592,7 @@ func (s *WALStore) WriteContext(ctx context.Context, lba uint32, data []byte) (u
|
||||
appendStart := time.Now()
|
||||
var walRelOff uint64
|
||||
|
||||
walRelOff, err = s.appendWriteV3(lba, data, lsn, func() error { return s.writeBudgetError(ctx, deadline) })
|
||||
walRelOff, err = s.appendWriteV3(lba, data, lsn, func() error { return s.writeBudgetError(ctx, deadline, nil) })
|
||||
|
||||
s.instr.appendLatency.Observe(time.Since(appendStart))
|
||||
// A failed pwrite may still leave complete records or padding in the file.
|
||||
@@ -653,7 +653,7 @@ func (s *WALStore) WriteBatchContext(ctx context.Context, startLBA uint32, block
|
||||
}
|
||||
defer s.lifecycleMu.RUnlock()
|
||||
|
||||
if err := s.writeBudgetError(ctx, deadline); err != nil {
|
||||
if err := s.writeBudgetError(ctx, deadline, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fastLocked, err := s.lockFastWALAppend(ctx, deadline, len(blocks))
|
||||
@@ -690,14 +690,14 @@ func (s *WALStore) WriteBatchContext(ctx context.Context, startLBA uint32, block
|
||||
s.mu.Unlock()
|
||||
return nil, err
|
||||
}
|
||||
if err := s.writeBudgetError(ctx, deadline); err != nil {
|
||||
if err := s.writeBudgetError(ctx, deadline, nil); err != nil {
|
||||
s.mu.Unlock()
|
||||
return nil, err
|
||||
}
|
||||
firstLSN := s.nextLSN
|
||||
{
|
||||
|
||||
lsns, err := s.writeBatchV3Locked(startLBA, blocks, firstLSN, func() error { return s.writeBudgetError(ctx, deadline) })
|
||||
lsns, err := s.writeBatchV3Locked(startLBA, blocks, firstLSN, func() error { return s.writeBudgetError(ctx, deadline, nil) })
|
||||
s.mu.Unlock()
|
||||
return lsns, err
|
||||
}
|
||||
|
||||
@@ -31,13 +31,9 @@ func (s *WALStore) writeAdmissionDeadline(ctx context.Context) time.Time {
|
||||
return time.Time{} // preserve legacy admission policy
|
||||
}
|
||||
|
||||
func (s *WALStore) writeBudgetError(ctx context.Context, deadline time.Time) error {
|
||||
return s.writeBudgetErrorFreed(ctx, deadline, nil)
|
||||
}
|
||||
|
||||
// writeBudgetErrorFreed is writeBudgetError with the hold's last look at the
|
||||
// freed space (walWriteHold.check).
|
||||
func (s *WALStore) writeBudgetErrorFreed(ctx context.Context, deadline time.Time, freed func() bool) error {
|
||||
// freed is the hold's look at the freed space at its stall boundary
|
||||
// (walWriteHold.check); nil when the caller has no WAL sample of its own.
|
||||
func (s *WALStore) writeBudgetError(ctx context.Context, deadline time.Time, freed func() bool) error {
|
||||
if err := s.stickyIOFault(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -66,7 +62,7 @@ func (s *WALStore) acquireWriteLock(ctx context.Context, deadline time.Time, try
|
||||
lock()
|
||||
return nil
|
||||
}
|
||||
if err := s.writeBudgetError(ctx, deadline); err != nil {
|
||||
if err := s.writeBudgetError(ctx, deadline, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if try() {
|
||||
@@ -75,7 +71,7 @@ func (s *WALStore) acquireWriteLock(ctx context.Context, deadline time.Time, try
|
||||
tick := time.NewTicker(time.Millisecond)
|
||||
defer tick.Stop()
|
||||
for {
|
||||
if err := s.writeBudgetError(ctx, deadline); err != nil {
|
||||
if err := s.writeBudgetError(ctx, deadline, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if try() {
|
||||
@@ -83,7 +79,7 @@ func (s *WALStore) acquireWriteLock(ctx context.Context, deadline time.Time, try
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return s.writeBudgetError(ctx, deadline)
|
||||
return s.writeBudgetError(ctx, deadline, nil)
|
||||
case <-tick.C:
|
||||
}
|
||||
}
|
||||
@@ -104,7 +100,7 @@ func (s *WALStore) writePressureSample(ctx context.Context, deadline time.Time)
|
||||
// The space is read before the budget answers: a stall is not answered
|
||||
// while the WAL is already below the hard mark (walWriteHold.check).
|
||||
freed := func() bool { return s.admission != nil && s.walPressureRLocked() < s.admission.hardMark }
|
||||
if err := s.writeBudgetErrorFreed(ctx, deadline, freed); err != nil {
|
||||
if err := s.writeBudgetError(ctx, deadline, freed); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if s.closed {
|
||||
|
||||
Reference in new issue
Block a user