Skip to content

Commit

Permalink
feat(client): add allowed logstream list option to varlog client
Browse files Browse the repository at this point in the history
  • Loading branch information
hungryjang committed Oct 6, 2022
1 parent 0b64855 commit 1ce80e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/varlog/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func (v *logImpl) append(ctx context.Context, tpid types.TopicID, lsid types.Log
result.Err = multierr.Append(result.Err, err)
continue
}
if _, ok = appendOpts.allowLogStreams[lsid]; appendOpts.allowLogStreams != nil && !ok {
err := fmt.Errorf("append: not allowed lsid %d", lsid)
result.Err = multierr.Append(result.Err, err)
continue
}
}
res, err := v.appendTo(ctx, tpid, lsid, data)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/varlog/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/kakao/varlog/pkg/types"
)

const (
Expand Down Expand Up @@ -152,6 +154,7 @@ func defaultAppendOptions() appendOptions {
type appendOptions struct {
retryCount int
selectLogStream bool
allowLogStreams map[types.LogStreamID]struct{}
}

type AppendOption interface {
Expand Down Expand Up @@ -182,6 +185,12 @@ func withoutSelectLogStream() AppendOption {
})
}

func WithAllowLogStreams(logStreams map[types.LogStreamID]struct{}) AppendOption {
return newAppendOption(func(opts *appendOptions) {
opts.allowLogStreams = logStreams
})
}

func defaultSubscribeOptions() subscribeOptions {
return subscribeOptions{
timeout: defaultSubscribeTimeout,
Expand Down

0 comments on commit 1ce80e7

Please sign in to comment.