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

Add high level job object wrapper #877

Merged
merged 1 commit into from
Dec 2, 2020
Merged

Conversation

dcantah
Copy link
Contributor

@dcantah dcantah commented Sep 16, 2020

  • Add high level job object wrapper.
  • Add extra job object bindings for stats usage.

Signed-off-by: Daniel Canter [email protected]

@dcantah dcantah requested a review from a team as a code owner September 16, 2020 16:32
internal/jobcontainers/job.go Outdated Show resolved Hide resolved
internal/jobcontainers/job.go Outdated Show resolved Hide resolved
internal/jobcontainers/job_test.go Outdated Show resolved Hide resolved
internal/jobcontainers/job.go Outdated Show resolved Hide resolved
internal/jobcontainers/job.go Outdated Show resolved Hide resolved
internal/jobcontainers/job.go Outdated Show resolved Hide resolved
@dcantah
Copy link
Contributor Author

dcantah commented Oct 15, 2020

@kevpar @katiewasnothere @ambarve If anyone has time tomorrow, could you give this a glance

internal/jobobject/queue.go Outdated Show resolved Hide resolved
internal/queue/mq.go Outdated Show resolved Hide resolved
@dcantah dcantah force-pushed the jobwrapper branch 2 times, most recently from f8d9d8a to c398a8a Compare November 13, 2020 22:36
Copy link
Contributor

@ambarve ambarve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments.

for {
err := winapi.GetQueuedCompletionStatus(iocpHandle, &code, &key, (**windows.Overlapped)(unsafe.Pointer(&overlapped)), windows.INFINITE)
if err != nil {
log.G(ctx).WithError(err).Error("failed to poll for job object message")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this is some non-transient error i.e some error which won't be resolved by the time of next iteration? We will keep looping with no way of breaking out of the loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From asking around, I couldn't find such a case for this call so I didn't worry about it. In go-winio, we check if nothing was filled in for the overlapped struct and if not we just panic so I think this is a little more friendly at least.https://github.com/microsoft/go-winio/blob/5b44b70ab3ab4d291a7c1d28afe7b4afeced0ed4/file.go#L162

Copy link
Contributor

@ambarve ambarve Nov 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds fine. Do you think we should add a check for context Done()and break from this loop in that case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, that's a bad idea. The ctx which was actually used during a call to this function could be cancelled but then that will stop this loop for all other jobs.

internal/jobobject/iocp.go Outdated Show resolved Hide resolved
internal/jobobject/iocp.go Show resolved Hide resolved
internal/jobobject/iocp.go Show resolved Hide resolved
internal/jobobject/jobobject.go Outdated Show resolved Hide resolved
internal/jobobject/jobobject.go Show resolved Hide resolved
internal/queue/mq.go Outdated Show resolved Hide resolved
internal/queue/queue_test.go Show resolved Hide resolved
internal/queue/queue_test.go Show resolved Hide resolved
internal/queue/queue_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@katiewasnothere katiewasnothere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

mq.closed = true
// If there's anybody currently waiting on a value from ReadOrWait, we need to
// signal so the read can return ErrQueueClosed.
mq.c.Signal()
Copy link
Contributor

@ambarve ambarve Nov 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still kind of confused about this. What happens if multiple goroutines call ReadOrWait() and are waiting for a notification to arrive but someone closes the queue before that. With the Signal call we will only wake one of them from the sleep right? Shouldn't all the goroutines wake up from their sleep and return ErrQueueEmpty?
We don't have any tests that tests this scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this should be broadcast, good call. For the write case it should just be signal but agreed here we should wake up everyone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, for the write case we should only wake up one thread with a Signal call. Maybe I typed this comment near the write function in previous version and that caused the confusion. Haha.

@ambarve
Copy link
Contributor

ambarve commented Nov 20, 2020

One small fix about using Broadcast vs Signal but otherwise LGTM!

* Add high level job object wrapper.
* Add extra job object bindings for stats usage.

Signed-off-by: Daniel Canter <[email protected]>
@dcantah
Copy link
Contributor Author

dcantah commented Nov 20, 2020

@kevpar If you have some time to do a last sweep :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants