-
Notifications
You must be signed in to change notification settings - Fork 122
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
chore: skip publishing the last empty struct when generator stops #2327
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package util | ||
|
||
import "reflect" | ||
|
||
// IsZeroStruct checks if a struct is zero value. | ||
func IsZeroStruct(v interface{}) bool { | ||
val := reflect.ValueOf(v) | ||
for i := 0; i < val.NumField(); i++ { | ||
field := val.Field(i) | ||
if !field.IsZero() { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package util | ||
|
||
import "testing" | ||
|
||
func TestIsZeroStruct(t *testing.T) { | ||
type args struct { | ||
v interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "zero_struct", | ||
args: args{v: struct { | ||
Name string | ||
Age int | ||
}{}}, | ||
want: true, | ||
}, | ||
{ | ||
name: "non_zero_struct", | ||
args: args{v: struct { | ||
Name string | ||
Age int | ||
}{ | ||
Name: "John", | ||
Age: 25, | ||
}}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := IsZeroStruct(tt.args.v); got != tt.want { | ||
t.Errorf("IsZeroStruct() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ import ( | |
dfv1 "github.com/numaproj/numaflow/pkg/apis/numaflow/v1alpha1" | ||
"github.com/numaproj/numaflow/pkg/isb" | ||
"github.com/numaproj/numaflow/pkg/shared/logging" | ||
"github.com/numaproj/numaflow/pkg/shared/util" | ||
"github.com/numaproj/numaflow/pkg/sources/sourcer" | ||
) | ||
|
||
|
@@ -198,6 +199,13 @@ loop: | |
// we implement Read With Wait semantics | ||
select { | ||
case r := <-mg.srcChan: | ||
// when the channel is closed and empty, go will still read from the channel once and return the zero value. | ||
// exclude the zero value from being passed to the next vertex, | ||
// ensuring all messages produced by generator follow the same data schema. | ||
if util.IsZeroStruct(r) { | ||
mg.logger.Info("Zero value read from the generator channel, skipping...") | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, shall we return instead of continue? |
||
} | ||
msgs = append(msgs, mg.newReadMessage(r.key, r.data, r.offset, r.ts)) | ||
case <-timeout: | ||
break loop | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it
zerostruct
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I updated the PR description and addressed the comment. Don't need the isZero check, just use the second parameter should work.