Skip to content

Commit 9559e47

Browse files
author
imakunin
committed
Merge branch 'master' into hoxo/serialize-mount-operations
2 parents 4c9049c + d516052 commit 9559e47

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

lzy/allocator/src/main/java/ai/lzy/allocator/AllocatorMain.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ public void destroyAllForTests() throws SQLException {
178178
}
179179
}
180180
});
181-
182-
System.out.println("!!!");
183181
}
184182

185183
public static void main(String[] args) throws IOException, InterruptedException {

lzy/allocator/src/main/java/ai/lzy/allocator/services/AllocatorService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,8 @@ public void forceFree(ForceFreeRequest request, StreamObserver<LongRunning.Opera
589589
ForceFreeResponse.getDefaultInstance()));
590590
}
591591

592-
if (vm.status() != Vm.Status.RUNNING) {
593-
LOG.error("ForceFree vm {} in status {}, expected RUNNING", vm, vm.status());
592+
if (vm.status() != Vm.Status.RUNNING && vm.status() != Vm.Status.IDLE) {
593+
LOG.error("ForceFree vm {} in status {}, expected RUNNING or IDLE", vm, vm.status());
594594
return Either.left(Status.FAILED_PRECONDITION.withDescription("State is " + vm.status()));
595595
}
596596

@@ -616,7 +616,11 @@ public void forceFree(ForceFreeRequest request, StreamObserver<LongRunning.Opera
616616
LOG.info("VM {} scheduled to remove (force free)", vm.vmId());
617617

618618
allocationContext.startNew(action);
619-
allocationContext.metrics().runningVms.labels(vm.poolLabel()).dec();
619+
620+
switch (vm.status()) {
621+
case RUNNING -> allocationContext.metrics().runningVms.labels(vm.poolLabel()).dec();
622+
case IDLE -> allocationContext.metrics().cachedVms.labels(vm.poolLabel()).dec();
623+
}
620624

621625
return Either.right(op);
622626
}

lzy/allocator/src/test/java/ai/lzy/allocator/test/AllocatorServiceTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,26 @@ public void allocateFromCache() throws Exception {
438438
assertVmMetrics("S", 0, 0, 0);
439439
}
440440

441+
@Test
442+
public void forceFreeFromCache() throws Exception {
443+
var sessionId = createSession(Durations.fromSeconds(10));
444+
445+
final CountDownLatch kuberRemoveRequestLatch = new CountDownLatch(1);
446+
447+
var firstVm = allocateAndFreeVm(sessionId,
448+
vm -> mockDeletePodByName(vm.podName(), kuberRemoveRequestLatch::countDown, HttpURLConnection.HTTP_OK));
449+
450+
assertVmMetrics("S", -1, 0, 1);
451+
452+
var forceFreeOp = forceFreeVm(firstVm.vmId());
453+
waitOpSuccess(forceFreeOp);
454+
assertVmMetrics("S", -1, 0, 0);
455+
456+
var secondVm = allocateVm(sessionId, "S", null);
457+
Assert.assertNotEquals(firstVm.vmId(), secondVm.vmId());
458+
assertVmMetrics("S", -1, 1, 0);
459+
}
460+
441461
@Test
442462
public void allocateConcurrentFromCache() throws Exception {
443463
var sessionId = createSession(Durations.fromSeconds(5000));

pylzy/lzy/api/v1/env.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212

1313
import yaml
1414

15-
from pypi_simple import PYPI_SIMPLE_ENDPOINT
16-
17-
from lzy.py_env.api import PyEnv
1815
from lzy.logs.config import get_logger
16+
from lzy.py_env.api import PyEnv
1917
from lzy.utils.pypi import validate_pypi_index_url
2018

2119
_LOG = get_logger(__name__)
@@ -158,7 +156,7 @@ def generate_conda_config(self) -> Dict[str, Any]:
158156
if python_version in _INSTALLED_VERSIONS:
159157
env_name = _INSTALLED_VERSIONS[python_version]
160158
else:
161-
_LOG.warn(
159+
_LOG.warning(
162160
f"Installed python version ({python_version}) is not cached remotely. "
163161
f"Usage of a cached python version ({list(_INSTALLED_VERSIONS.keys())}) "
164162
f"can decrease startup time."

pylzy/lzy/api/v1/utils/proxy_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def materialize_if_sequence_of_lzy_proxies(obj: Any) -> Any:
4545
if is_lzy_proxy(elem):
4646
result.append(materialize(elem))
4747

48-
if type(obj) == tuple:
48+
if type(obj) is tuple:
4949
return tuple(result)
5050
return result
5151

pylzy/tests/api/v1/test_workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def test_materialize(self):
356356
def test_lazy_args_loading(self):
357357
@op(lazy_arguments=True)
358358
def is_arg_type_str(a: str) -> bool:
359-
return type(a) == str
359+
return type(a) is str
360360

361361
with self.lzy.workflow("test"):
362362
res = is_arg_type_str("str")
@@ -365,7 +365,7 @@ def is_arg_type_str(a: str) -> bool:
365365
def test_eager_args_loading(self):
366366
@op(lazy_arguments=False)
367367
def is_arg_type_str(a: str) -> bool:
368-
return type(a) == str
368+
return type(a) is str
369369

370370
with self.lzy.workflow("test"):
371371
res = is_arg_type_str("str")

0 commit comments

Comments
 (0)