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

Expose freezer sink flush interval. #66

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
16 changes: 13 additions & 3 deletions freezer/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
)

type AsyncMessageSinkConfig struct {
FlushInterval time.Duration
StreamStore straw.StreamStore
FreezerConfig freezer.MessageSinkConfig
}
Expand All @@ -25,11 +26,20 @@ func NewAsyncMessageSink(config AsyncMessageSinkConfig) (substrate.AsyncMessageS
if err != nil {
return nil, err
}
return &asyncMessageSink{fms}, nil

flushInterval := config.FlushInterval
if flushInterval == 0 {
flushInterval = time.Second
}
return &asyncMessageSink{
flushInterval: flushInterval,
fms: fms,
}, nil
}

type asyncMessageSink struct {
fms *freezer.MessageSink
flushInterval time.Duration
fms *freezer.MessageSink
}

func (ams *asyncMessageSink) PublishMessages(ctx context.Context, acks chan<- substrate.Message, messages <-chan substrate.Message) (rerr error) {
Expand All @@ -49,7 +59,7 @@ func (ams *asyncMessageSink) PublishMessages(ctx context.Context, acks chan<- su
default:
}
}
t.Reset(1000 * time.Millisecond)
t.Reset(ams.flushInterval)
if err := ams.fms.PutMessage(m.Data()); err != nil {
return err
}
Expand Down
13 changes: 12 additions & 1 deletion freezer/freezer_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ func newFreezerSink(u *url.URL) (substrate.AsyncMessageSink, error) {

q := u.Query()

var flushInterval time.Duration
if fi := q.Get("flush-interval"); fi != "" {
dur, err := time.ParseDuration(fi)
if err != nil {
return nil, err
}
flushInterval = dur
}

cts := q.Get("compression")
ct := freezer.CompressionTypeNone
switch cts {
Expand All @@ -44,6 +53,7 @@ func newFreezerSink(u *url.URL) (substrate.AsyncMessageSink, error) {

sse := q.Get("sse")
switch sse {
case "":
case "aes256":
enc = straw.S3ServerSideEncoding(straw.ServerSideEncryptionTypeAES256)
default:
Expand All @@ -62,7 +72,8 @@ func newFreezerSink(u *url.URL) (substrate.AsyncMessageSink, error) {
return nil, fmt.Errorf("unsupported scheme : %s", u.Scheme)
}
conf := AsyncMessageSinkConfig{
StreamStore: streamstore,
FlushInterval: flushInterval,
StreamStore: streamstore,
FreezerConfig: freezer.MessageSinkConfig{
Path: u.Path,
CompressionType: ct,
Expand Down
3 changes: 2 additions & 1 deletion freezer/freezer_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ func TestFreezerSink(t *testing.T) {
},
{
name: "everything-dir",
input: "freezer+dir:///foo/bar2/baz/?compression=snappy",
input: "freezer+dir:///foo/bar2/baz/?compression=snappy&flush-interval=5s",
expected: AsyncMessageSinkConfig{
FlushInterval: time.Second * 5,
FreezerConfig: freezer.MessageSinkConfig{
CompressionType: freezer.CompressionTypeSnappy,
Path: "/foo/bar2/baz/",
Expand Down