Skip to content

Commit 763092d

Browse files
authored
Fix scaling during update to replica groups (#3510)
This fix prevents the number of replicas from dropping to `replicas.min` for all existing services during a server update to 0.20.7.
1 parent 7ba2f3c commit 763092d

File tree

1 file changed

+15
-1
lines changed
  • src/dstack/_internal/server/services/services

1 file changed

+15
-1
lines changed

src/dstack/_internal/server/services/services/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
ServerClientError,
2020
SSHError,
2121
)
22-
from dstack._internal.core.models.configurations import SERVICE_HTTPS_DEFAULT, ServiceConfiguration
22+
from dstack._internal.core.models.configurations import (
23+
DEFAULT_REPLICA_GROUP_NAME,
24+
SERVICE_HTTPS_DEFAULT,
25+
ServiceConfiguration,
26+
)
2327
from dstack._internal.core.models.gateways import GatewayConfiguration, GatewayStatus
2428
from dstack._internal.core.models.instances import SSHConnectionParams
2529
from dstack._internal.core.models.runs import JobSpec, Run, RunSpec, ServiceModelSpec, ServiceSpec
@@ -318,8 +322,18 @@ async def update_service_desired_replica_count(
318322
prev_counts = (
319323
json.loads(run_model.desired_replica_counts) if run_model.desired_replica_counts else {}
320324
)
325+
if (
326+
prev_counts == {}
327+
and len(replica_groups) == 1
328+
and replica_groups[0].name == DEFAULT_REPLICA_GROUP_NAME
329+
):
330+
# Special case to avoid dropping the replica count to group.count.min
331+
# when a 0.20.7+ server first processes a service created by a pre-0.20.7 server.
332+
# TODO: remove once most users upgrade to 0.20.7+.
333+
prev_counts = {DEFAULT_REPLICA_GROUP_NAME: run_model.desired_replica_count}
321334
for group in replica_groups:
322335
scaler = get_service_scaler(group.count, group.scaling)
336+
assert group.name is not None, "Group name is always set"
323337
group_desired = scaler.get_desired_count(
324338
current_desired_count=prev_counts.get(group.name, group.count.min or 0),
325339
stats=stats,

0 commit comments

Comments
 (0)