Skip to content

Commit

Permalink
fix: change the behaviour of debug messages
Browse files Browse the repository at this point in the history
Signed-off-by: arkbriar <[email protected]>
  • Loading branch information
arkbriar committed Aug 22, 2024
1 parent 375960f commit b8b46eb
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions internal/filechannel/filechannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ import (
"github.com/risingwavelabs/filechannel/internal/utils"
)

// The flag to control the debug output. Debug outputs should print the non-critical messages. All
// unexpected error messages must be printed without this flag.
var verbose, _ = strconv.ParseBool(os.Getenv("DEBUG"))

var (
ErrChecksumMismatch = errors.New("channel corrupted: checksum mismatch")
ErrChannelClosed = errors.New("channel closed")
Expand Down Expand Up @@ -1124,8 +1128,13 @@ func (fc *FileChannel) compress(ctx context.Context, index uint32) error {
default:
}

// Pin the segment. If failed, it means the watermark has moved forward and beyond the segment index.
// So we can just return immediately.
if !fc.segmentManager.Pin(index) {
return fmt.Errorf("failed to pin segment index %d", index)
if verbose {
_, _ = fmt.Fprintf(os.Stderr, "failed to pin segment index %d\n", index)
}
return nil
}
defer fc.segmentManager.Unpin(index)

Expand Down Expand Up @@ -1210,8 +1219,10 @@ func (fc *FileChannel) flushAndNotifyLoop(ctx context.Context) {
case <-ctx.Done():
return
case <-time.After(fc.flushInterval):
// FIXME: log the error
_ = fc.flushAndNotifyWithLock()
err := fc.flushAndNotifyWithLock()
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "failed to flush: %v\n", err)
}
}
}
}
Expand Down

0 comments on commit b8b46eb

Please sign in to comment.