Skip to content

Conversation

@ianchen0119
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings January 30, 2026 12:15
@ianchen0119
Copy link
Contributor Author

FYI @weiso131

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new GetNrQueued() API method to the Sched interface that returns the number of tasks currently queued and waiting to be dequeued. This method appears to support metrics reporting, as evidenced by the existing NrQueued field in the BssData struct used for metrics.

Changes:

  • Added GetNrQueued() uint64 method to the Sched interface in the registry
  • Implemented the method in three test mock schedulers (simple_test.go, gthulhu_test.go, factory_integration_test.go)
  • Minor formatting fix in factory_integration_test.go (closing brace placement)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
plugin/internal/registry/registry.go Added GetNrQueued() method to the Sched interface
plugin/simple/simple_test.go Implemented GetNrQueued() in MockScheduler test mock
plugin/gthulhu/gthulhu_test.go Implemented GetNrQueued() in MockScheduler test mock
tests/factory_integration_test.go Implemented GetNrQueued() in testSched mock and fixed formatting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return nil, cpu
}

func (m *MockScheduler) GetNrQueued() uint64 {
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The GetNrQueued implementation has a potential integer underflow issue. If queueIndex somehow becomes greater than len(m.taskQueue), the subtraction would produce a negative value which, when cast to uint64, would wrap around to a very large positive number. Consider adding a safety check: if m.queueIndex > len(m.taskQueue) { return 0 } before the calculation, or use: if m.queueIndex >= len(m.taskQueue) { return 0 } return uint64(len(m.taskQueue) - m.queueIndex)

Suggested change
func (m *MockScheduler) GetNrQueued() uint64 {
func (m *MockScheduler) GetNrQueued() uint64 {
if m.queueIndex >= len(m.taskQueue) {
return 0
}

Copilot uses AI. Check for mistakes.
return nil, 0
}

func (s *testSched) GetNrQueued() uint64 {
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The GetNrQueued implementation has a potential integer underflow issue. If index somehow becomes greater than len(s.tasks), the subtraction would produce a negative value which, when cast to uint64, would wrap around to a very large positive number. Consider adding a safety check: if s.index > len(s.tasks) { return 0 } before the calculation, or use: if s.index >= len(s.tasks) { return 0 } return uint64(len(s.tasks) - s.index)

Suggested change
func (s *testSched) GetNrQueued() uint64 {
func (s *testSched) GetNrQueued() uint64 {
if s.index >= len(s.tasks) {
return 0
}

Copilot uses AI. Check for mistakes.
Comment on lines +166 to +168
func (m *MockScheduler) GetNrQueued() uint64 {
return uint64(len(m.taskQueue) - m.queueIndex)
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The newly added GetNrQueued method is not called or tested anywhere in the codebase. Consider adding unit tests that verify the method returns correct values in various scenarios (e.g., empty queue, partially dequeued queue, fully dequeued queue) to ensure the implementation works as expected.

Copilot uses AI. Check for mistakes.
@@ -12,6 +12,7 @@ import (
type Sched interface {
DequeueTask(task *models.QueuedTask)
DefaultSelectCPU(t *models.QueuedTask) (error, int32)
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The new GetNrQueued method lacks documentation. Consider adding a comment explaining its purpose and expected behavior, similar to how other interface methods are documented. For example: "GetNrQueued returns the number of tasks currently queued and waiting to be dequeued."

Suggested change
DefaultSelectCPU(t *models.QueuedTask) (error, int32)
DefaultSelectCPU(t *models.QueuedTask) (error, int32)
// GetNrQueued returns the number of tasks currently queued and waiting to be dequeued.

Copilot uses AI. Check for mistakes.
return nil, cpu
}

func (m *MockScheduler) GetNrQueued() uint64 {
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The GetNrQueued implementation has a potential integer underflow issue. If queueIndex somehow becomes greater than len(m.taskQueue), the subtraction would produce a negative value which, when cast to uint64, would wrap around to a very large positive number. Consider adding a safety check: if m.queueIndex > len(m.taskQueue) { return 0 } before the calculation, or use: if m.queueIndex >= len(m.taskQueue) { return 0 } return uint64(len(m.taskQueue) - m.queueIndex)

Suggested change
func (m *MockScheduler) GetNrQueued() uint64 {
func (m *MockScheduler) GetNrQueued() uint64 {
if m.queueIndex >= len(m.taskQueue) {
return 0
}

Copilot uses AI. Check for mistakes.
@ianchen0119 ianchen0119 merged commit 0dc1226 into main Jan 30, 2026
7 checks passed
@ianchen0119 ianchen0119 deleted the fix/race_condition branch January 30, 2026 12:47
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.

2 participants