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

chore: agent state wasn't getting deleted and logged error #8838

Merged
merged 2 commits into from
Feb 13, 2024
Merged
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
9 changes: 7 additions & 2 deletions master/internal/rm/agentrm/agent_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,13 @@ func (a *agentState) restoreContainersField() error {
}

func clearAgentStates(agentIds []agentID) error {
_, err := db.Bun().NewDelete().Model((*agentSnapshot)(nil)).Where("agent_id in (?)", agentIds).Exec(context.TODO())
return fmt.Errorf("clearing agent states: %w", err)
if _, err := db.Bun().NewDelete().Model((*agentSnapshot)(nil)).
Where("agent_id in (?)", bun.In(agentIds)).
Exec(context.TODO()); err != nil {
return fmt.Errorf("clearing agent states: %w", err)
}

return nil
}

func updateContainerState(c *cproto.Container) error {
Expand Down
23 changes: 23 additions & 0 deletions master/internal/rm/agentrm/agent_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/uptrace/bun"

"github.com/determined-ai/determined/master/internal/db"
"github.com/determined-ai/determined/master/internal/sproto"
Expand Down Expand Up @@ -184,6 +185,28 @@ func TestAgentStatePersistence(t *testing.T) {
require.False(t, exists)
}

func TestClearAgentStates(t *testing.T) {
ctx := context.Background()
agentIDs := []agentID{agentID(uuid.NewString()), agentID(uuid.NewString())}
for _, agentID := range agentIDs {
_, err := db.Bun().NewInsert().Model(&agentSnapshot{
AgentID: agentID,
UUID: uuid.NewString(),
ResourcePoolName: "rp-name",
Label: "label",
MaxZeroSlotContainers: 0,
}).Exec(ctx)
require.NoError(t, err)
}

require.NoError(t, clearAgentStates(agentIDs))
exists, err := db.Bun().NewSelect().Model(&agentSnapshot{}).
Where("agent_id IN (?)", bun.In(agentIDs)).
Exists(ctx)
require.NoError(t, err)
require.False(t, exists)
}

func Test_agentState_checkAgentStartedDevicesMatch(t *testing.T) {
stableUUID := uuid.NewString()
tests := []struct {
Expand Down
Loading