Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- Creating or updating a database with a node name that isn't "n" followed by a number, such as "n1-east", now returns a 400 error that names the node and the expected format, instead of a 500 server error. The same node name format is now enforced for the node names in backup, switchover, failover, and restore requests.
- A scheduled switchover's task now stays running until the switchover happens, and canceling the task before the scheduled time cancels the switchover. Previously, the task completed as soon as the switchover was scheduled and could no longer be canceled. A scheduled switchover is now skipped if the primary changes before the scheduled time, it fails rather than running more than 5 minutes late, and it uses the node's current hosts at the scheduled time. Requesting a switchover or failover for a node that already has one in progress now returns a 409 operation_already_in_progress error instead of a 500 server error.
- Replicas of Spock 6 databases on Postgres 17 or later now drop stale copies of Spock replication slots, including after a switchover or failover, so that native slot synchronization keeps their copies current. Creating or updating a replica no longer fails when its slot copies stay temporary, and an update doesn't switch over to a replica that lacks them.
- Creating or updating a database now reports every invalid service in one error instead of only the first one. On hosts that use the systemd orchestrator, the error now says when a service isn't installed, for example `service 'postgrest' is not installed on host 'host-1'`.

### Security

Expand Down
1 change: 1 addition & 0 deletions changes/v1.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- Creating or updating a database with a node name that isn't "n" followed by a number, such as "n1-east", now returns a 400 error that names the node and the expected format, instead of a 500 server error. The same node name format is now enforced for the node names in backup, switchover, failover, and restore requests.
- A scheduled switchover's task now stays running until the switchover happens, and canceling the task before the scheduled time cancels the switchover. Previously, the task completed as soon as the switchover was scheduled and could no longer be canceled. A scheduled switchover is now skipped if the primary changes before the scheduled time, it fails rather than running more than 5 minutes late, and it uses the node's current hosts at the scheduled time. Requesting a switchover or failover for a node that already has one in progress now returns a 409 operation_already_in_progress error instead of a 500 server error.
- Replicas of Spock 6 databases on Postgres 17 or later now drop stale copies of Spock replication slots, including after a switchover or failover, so that native slot synchronization keeps their copies current. Creating or updating a replica no longer fails when its slot copies stay temporary, and an update doesn't switch over to a replica that lacks them.
- Creating or updating a database now reports every invalid service in one error instead of only the first one. On hosts that use the systemd orchestrator, the error now says when a service isn't installed, for example `service 'postgrest' is not installed on host 'host-1'`.

### Security

Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- Creating or updating a database with a node name that isn't "n" followed by a number, such as "n1-east", now returns a 400 error that names the node and the expected format, instead of a 500 server error. The same node name format is now enforced for the node names in backup, switchover, failover, and restore requests.
- A scheduled switchover's task now stays running until the switchover happens, and canceling the task before the scheduled time cancels the switchover. Previously, the task completed as soon as the switchover was scheduled and could no longer be canceled. A scheduled switchover is now skipped if the primary changes before the scheduled time, it fails rather than running more than 5 minutes late, and it uses the node's current hosts at the scheduled time. Requesting a switchover or failover for a node that already has one in progress now returns a 409 operation_already_in_progress error instead of a 500 server error.
- Replicas of Spock 6 databases on Postgres 17 or later now drop stale copies of Spock replication slots, including after a switchover or failover, so that native slot synchronization keeps their copies current. Creating or updating a replica no longer fails when its slot copies stay temporary, and an update doesn't switch over to a replica that lacks them.
- Creating or updating a database now reports every invalid service in one error instead of only the first one. On hosts that use the systemd orchestrator, the error now says when a service isn't installed, for example `service 'postgrest' is not installed on host 'host-1'`.

### Security

Expand Down
2 changes: 1 addition & 1 deletion e2e/rag_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ func TestProvisionRAGServiceUnsupportedVersion(t *testing.T) {
require.Error(t, err, "CreateDatabase should reject an unsupported service version")
assert.ErrorIs(t, err, client.ErrInvalidInput, "Error should be invalid input")
assert.Nil(t, createResp, "CreateDatabase should not return a response")
assert.Contains(t, err.Error(), "does not support rag version 99.99.99", "Error should name the unsupported version")
assert.Contains(t, err.Error(), "99.99.99", "Error should name the unsupported version")
t.Logf("CreateDatabase rejected as expected: %s", err)

t.Log("RAG unsupported version test completed successfully")
Expand Down
4 changes: 2 additions & 2 deletions e2e/service_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func TestProvisionMCPServiceUnsupportedVersion(t *testing.T) {
require.Error(t, err, "CreateDatabase should reject an unsupported service version")
assert.ErrorIs(t, err, client.ErrInvalidInput, "Error should be invalid input")
assert.Nil(t, createResp, "CreateDatabase should not return a response")
assert.Contains(t, err.Error(), "does not support mcp version 99.99.99", "Error should name the unsupported version")
assert.Contains(t, err.Error(), "99.99.99", "Error should name the unsupported version")

t.Logf("CreateDatabase rejected as expected: %s", err)

Expand Down Expand Up @@ -556,7 +556,7 @@ func TestProvisionMCPServiceRecovery(t *testing.T) {
})
require.Error(t, err, "UpdateDatabase should reject an unsupported service version")
assert.ErrorIs(t, err, client.ErrInvalidInput, "Error should be invalid input")
assert.Contains(t, err.Error(), "does not support mcp version 99.99.99", "Error should name the unsupported version")
assert.Contains(t, err.Error(), "99.99.99", "Error should name the unsupported version")
t.Logf("UpdateDatabase rejected as expected: %s", err)

// The rejected update must not have been applied
Expand Down
31 changes: 25 additions & 6 deletions server/internal/database/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,19 +665,23 @@ func (s *Service) PopulateSpecDefaults(ctx context.Context, spec, current *Spec)
}

// validateServiceHosts validates that every service's host IDs refer to
// registered hosts that can run the requested service version.
// registered hosts that can run the requested service version. It returns
// every problem it finds, rather than only the first one.
func validateServiceHosts(services []*ServiceSpec, hostsByID map[string]*host.Host) error {
var errs []error
for _, svc := range services {
var knownHosts []*host.Host
for _, hostID := range svc.HostIDs {
h, ok := hostsByID[hostID]
if !ok {
return fmt.Errorf("service %q: host %s not found", svc.ServiceID, hostID)
errs = append(errs, fmt.Errorf("service %q: host %s not found", svc.ServiceID, hostID))
continue
}
if h.Orchestrator == config.OrchestratorSystemD && svc.Port == nil {
// systemd service instances listen on the host directly, so
// they're unreachable without a port.
return fmt.Errorf("service %q: port is required for host %s, which uses the systemd orchestrator. set it to 0 to assign a random port", svc.ServiceID, h.ID)
errs = append(errs, fmt.Errorf("service %q: port is required for host %s, which uses the systemd orchestrator. set it to 0 to assign a random port", svc.ServiceID, h.ID))
continue
}
if h.SupportedServices == nil {
// This host's record was written by a Control Plane version
Expand All @@ -690,7 +694,8 @@ func validateServiceHosts(services []*ServiceSpec, hostsByID map[string]*host.Ho
continue
}
if !h.SupportsService(svc.ServiceType, svc.Version) {
return fmt.Errorf("service %q: host %s does not support %s version %s", svc.ServiceID, h.ID, svc.ServiceType, svc.Version)
errs = append(errs, unsupportedServiceError(svc, h))
continue
}
knownHosts = append(knownHosts, h)
}
Expand All @@ -699,12 +704,26 @@ func validateServiceHosts(services []*ServiceSpec, hostsByID map[string]*host.Ho
// hosts' defaults, but each host resolves it to its own default,
// so they must agree for every instance to run the same version.
if _, err := host.CommonDefaultServiceVersion(svc.ServiceType, knownHosts...); err != nil {
return fmt.Errorf("service %q: unable to resolve version %s: %w", svc.ServiceID, svc.Version, err)
errs = append(errs, fmt.Errorf("service %q: unable to resolve version %s: %w", svc.ServiceID, svc.Version, err))
}
}
}

return nil
return errors.Join(errs...)
}

// unsupportedServiceError returns the error for a host that can't run the
// given service version. A systemd host only supports the version of each
// service that's installed on it, while a swarm host supports the versions in
// the version manifest.
func unsupportedServiceError(svc *ServiceSpec, h *host.Host) error {
if h.Orchestrator != config.OrchestratorSystemD {
return fmt.Errorf("service %q: host %s does not support %s version %s", svc.ServiceID, h.ID, svc.ServiceType, svc.Version)
}
if svc.Version == host.ServiceVersionLatest {
return fmt.Errorf("service '%s' is not installed on host '%s'", svc.ServiceType, h.ID)
}
return fmt.Errorf("service '%s' version '%s' is not installed on host '%s'", svc.ServiceType, svc.Version, h.ID)
}

func (s *Service) ReconcileInstanceSpec(ctx context.Context, spec *InstanceSpec) (*InstanceSpec, error) {
Expand Down
38 changes: 37 additions & 1 deletion server/internal/database/spec_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package database

import (
"maps"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -165,6 +166,12 @@ func TestValidateServiceHosts(t *testing.T) {
SupportedServices: map[string][]string{"postgrest": {"14.5"}},
DefaultServiceVersions: map[string]string{"postgrest": "14.5"},
},
"host-systemd-2": {
ID: "host-systemd-2",
Orchestrator: config.OrchestratorSystemD,
SupportedServices: map[string][]string{},
DefaultServiceVersions: map[string]string{},
},
}
postgrest := func(version string, hostIDs ...string) *ServiceSpec {
return &ServiceSpec{
Expand Down Expand Up @@ -219,7 +226,16 @@ func TestValidateServiceHosts(t *testing.T) {
svc.OrchestratorOpts = &OrchestratorOpts{Swarm: &SwarmOpts{Image: "registry.example.com/postgrest:dev"}}
return svc
}(),
expectedErr: `service "api": host host-systemd does not support postgrest version 99.0`,
expectedErr: `service 'postgrest' version '99.0' is not installed on host 'host-systemd'`,
},
{
name: "service not installed on a systemd host",
service: func() *ServiceSpec {
svc := postgrest("latest", "host-systemd-2")
svc.Port = utils.PointerTo(0)
return svc
}(),
expectedErr: `service 'postgrest' is not installed on host 'host-systemd-2'`,
},
{
name: "host without supported services is not validated",
Expand Down Expand Up @@ -253,6 +269,26 @@ func TestValidateServiceHosts(t *testing.T) {
}
})
}

t.Run("returns every error", func(t *testing.T) {
mcp := &ServiceSpec{
ServiceID: "mcp-server",
ServiceType: "mcp",
Version: "latest",
HostIDs: []string{"host-systemd", "host-systemd-2"},
Port: utils.PointerTo(0),
}
api := postgrest("latest", "host-systemd", "host-systemd-2", "host-5")
api.Port = utils.PointerTo(0)

err := validateServiceHosts([]*ServiceSpec{api, mcp}, hostsByID)
assert.EqualError(t, err, strings.Join([]string{
`service 'postgrest' is not installed on host 'host-systemd-2'`,
`service "api": host host-5 not found`,
`service 'mcp' is not installed on host 'host-systemd'`,
`service 'mcp' is not installed on host 'host-systemd-2'`,
}, "\n"))
})
}

func TestValidateSpockRequirements(t *testing.T) {
Expand Down