Skip to content
Open
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
11 changes: 10 additions & 1 deletion internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"time"

"github.com/sirupsen/logrus"
"github.com/yisaer/file-rotatelogs"
rotatelogs "github.com/yisaer/file-rotatelogs"

"github.com/lf-edge/ekuiper/v2/internal/conf/logger"
"github.com/lf-edge/ekuiper/v2/internal/pkg/def"
Expand Down Expand Up @@ -290,6 +290,15 @@ func ValidateRuleOption(option *def.RuleOption) error {
if err := schedule.ValidateRanges(option.CronDatetimeRange); err != nil {
errs = errors.Join(errs, fmt.Errorf("validate cronDatetimeRange failed, err:%v", err))
}
if option.Qos >= def.AtLeastOnce {
if option.DisableBufferFullDiscard == nil {
t := true
option.DisableBufferFullDiscard = &t
} else if !*option.DisableBufferFullDiscard {
Log.Warnf("QoS is %d but disableBufferFullDiscard is explicitly set to false, this may lead to silent data loss during congestion.", option.Qos)
Comment thread
pulkitvats2007-crypto marked this conversation as resolved.
errs = errors.Join(errs, fmt.Errorf("invalidDisableBufferFullDiscard:disableBufferFullDiscard must be true when qos is %d or higher", def.AtLeastOnce))
}
}
Comment thread
pulkitvats2007-crypto marked this conversation as resolved.
return errs
}

Expand Down
20 changes: 20 additions & 0 deletions internal/conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ func TestRuleOptionValidate(t *testing.T) {
},
},
},
{
s: &def.RuleOption{
Qos: def.AtLeastOnce,
},
e: &def.RuleOption{
Qos: def.AtLeastOnce,
DisableBufferFullDiscard: func() *bool { b := true; return &b }(),
},
},
{
s: &def.RuleOption{
Qos: def.AtLeastOnce,
DisableBufferFullDiscard: func() *bool { b := false; return &b }(),
},
e: &def.RuleOption{
Qos: def.AtLeastOnce,
DisableBufferFullDiscard: func() *bool { b := false; return &b }(),
},
err: "invalidDisableBufferFullDiscard:disableBufferFullDiscard must be true when qos is 1 or higher",
},
}
fmt.Printf("The test bucket size is %d.\n\n", len(tests))
for i, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/def/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type RuleOption struct {
CronDatetimeRange []schedule.DatetimeRange `json:"cronDatetimeRange,omitempty" yaml:"cronDatetimeRange,omitempty"`
PlanOptimizeStrategy *PlanOptimizeStrategy `json:"planOptimizeStrategy,omitempty" yaml:"planOptimizeStrategy,omitempty"`
NotifySub bool `json:"notifySub,omitempty" yaml:"notifySub,omitempty"`
DisableBufferFullDiscard bool `json:"disableBufferFullDiscard,omitempty" yaml:"disableBufferFullDiscard,omitempty"`
DisableBufferFullDiscard *bool `json:"disableBufferFullDiscard,omitempty" yaml:"disableBufferFullDiscard,omitempty"`
EnableSaveStateBeforeStop bool `json:"enableSaveStateBeforeStop,omitempty" yaml:"enableSaveStateBeforeStop,omitempty"`
Comment thread
ngjaying marked this conversation as resolved.
ForceExitTimeout cast.DurationConf `json:"forceExitTimeout,omitempty" yaml:"forceExitTimeout,omitempty"`
Experiment *ExpOpts `json:"experiment,omitempty" yaml:"experiment,omitempty"`
Expand Down
21 changes: 13 additions & 8 deletions internal/processor/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@ func TestRuleActionParse_Apply(t *testing.T) {
},
},
Options: &def.RuleOption{
IsEventTime: true,
LateTol: cast.DurationConf(time.Second),
Concurrency: 1,
BufferLength: 10240,
SendMetaToSink: false,
Qos: def.ExactlyOnce,
CheckpointInterval: cast.DurationConf(time.Minute),
SendError: false,
IsEventTime: true,
LateTol: cast.DurationConf(time.Second),
Concurrency: 1,
BufferLength: 10240,
SendMetaToSink: false,
Qos: def.ExactlyOnce,
CheckpointInterval: cast.DurationConf(time.Minute),
SendError: false,
DisableBufferFullDiscard: boolPtr(true),
RestartStrategy: &def.RestartStrategy{
Attempts: 0,
},
Expand Down Expand Up @@ -257,3 +258,7 @@ func TestAllRules(t *testing.T) {
}
assert.Equal(t, expected, all)
}

func boolPtr(b bool) *bool {
return &b
}
5 changes: 4 additions & 1 deletion internal/topo/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func newDefaultNode(name string, options *def.RuleOption) *defaultNode {
outputs: make(map[string]chan any),
concurrency: c,
sendError: options.SendError,
disableBufferFullDiscard: options.DisableBufferFullDiscard,
disableBufferFullDiscard: options.DisableBufferFullDiscard != nil && *options.DisableBufferFullDiscard,
Comment thread
pulkitvats2007-crypto marked this conversation as resolved.
}
}

Expand Down Expand Up @@ -98,6 +98,9 @@ func (o *defaultNode) GetName() string {

func (o *defaultNode) SetQos(qos def.Qos) {
o.qos = qos
if qos >= def.AtLeastOnce {
o.disableBufferFullDiscard = true
}
}
Comment thread
ngjaying marked this conversation as resolved.

func (o *defaultNode) GetMetrics() []any {
Expand Down
16 changes: 16 additions & 0 deletions internal/topo/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,19 @@ func TestMultipleOutputsBroadcast(t *testing.T) {
})
}
}

func TestSetQos(t *testing.T) {
tests := []struct {
qos def.Qos
expectedDisableBufferFullDiscard bool
}{
{qos: def.AtMostOnce, expectedDisableBufferFullDiscard: false},
{qos: def.AtLeastOnce, expectedDisableBufferFullDiscard: true},
{qos: def.ExactlyOnce, expectedDisableBufferFullDiscard: true},
}
for _, tt := range tests {
n := newDefaultNode("test", &def.RuleOption{})
n.SetQos(tt.qos)
assert.Equal(t, tt.expectedDisableBufferFullDiscard, n.disableBufferFullDiscard)
}
}
2 changes: 1 addition & 1 deletion internal/topo/planner/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func CreateLogicalPlan(stmt *ast.SelectStatement, opt *def.RuleOption, store kv.
}

func checkSharedSourceOption(streams []*streamInfo, opt *def.RuleOption) error {
if !opt.DisableBufferFullDiscard {
if opt.DisableBufferFullDiscard == nil || !*opt.DisableBufferFullDiscard {
return nil
}
for _, stream := range streams {
Expand Down
3 changes: 2 additions & 1 deletion internal/topo/planner/planner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4672,8 +4672,9 @@ func TestCheckSharedSourceOption(t *testing.T) {
},
},
}
b := true
r1 := &def.RuleOption{
DisableBufferFullDiscard: true,
DisableBufferFullDiscard: &b,
}
Comment thread
pulkitvats2007-crypto marked this conversation as resolved.
require.Error(t, checkSharedSourceOption(s1, r1))
}
7 changes: 4 additions & 3 deletions internal/topo/topotest/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,14 +1245,15 @@ func TestSingleSQL(t *testing.T) {
},
}
HandleStream(true, streamList, t)
bTrue := true
options := []*def.RuleOption{
{
BufferLength: 100,
SendError: true,
PlanOptimizeStrategy: &def.PlanOptimizeStrategy{
EnableIncrementalWindow: true,
},
DisableBufferFullDiscard: true,
DisableBufferFullDiscard: &bTrue,
},
{
BufferLength: 100,
Expand All @@ -1262,7 +1263,7 @@ func TestSingleSQL(t *testing.T) {
PlanOptimizeStrategy: &def.PlanOptimizeStrategy{
EnableIncrementalWindow: true,
},
DisableBufferFullDiscard: true,
DisableBufferFullDiscard: &bTrue,
},
{
BufferLength: 100,
Expand All @@ -1272,7 +1273,7 @@ func TestSingleSQL(t *testing.T) {
PlanOptimizeStrategy: &def.PlanOptimizeStrategy{
EnableIncrementalWindow: true,
},
DisableBufferFullDiscard: true,
DisableBufferFullDiscard: &bTrue,
},
}
for _, opt := range options {
Expand Down
Loading