Skip to content

Commit 495da58

Browse files
oavdeevwoop
authored andcommitted
fix job cache state leak between tests
Signed-off-by: Oleg Avdeev <oleg.v.avdeev@gmail.com>
1 parent 937a036 commit 495da58

3 files changed

Lines changed: 33 additions & 14 deletions

File tree

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
from .local import StandaloneClusterLauncher, StandaloneClusterRetrievalJob
1+
from .local import (
2+
StandaloneClusterLauncher,
3+
StandaloneClusterRetrievalJob,
4+
reset_job_cache,
5+
)
26

3-
__all__ = ["StandaloneClusterRetrievalJob", "StandaloneClusterLauncher"]
7+
__all__ = [
8+
"StandaloneClusterRetrievalJob",
9+
"StandaloneClusterLauncher",
10+
"reset_job_cache",
11+
]

sdk/python/feast/pyspark/launchers/standalone/local.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525

2626

2727
class JobCache:
28-
"""In-memory cache of Spark jobs.
29-
30-
This is necessary since we can't query Spark jobs in local mode
28+
"""
29+
A *global* in-memory cache of Spark jobs.
3130
31+
This is necessary since we can't easily keep track of running Spark jobs in local mode, since
32+
there is no external state (unlike EMR and Dataproc which keep track of the running jobs for
33+
us).
3234
"""
3335

3436
# Map of job_id -> spark job
@@ -75,7 +77,12 @@ def get_job_by_id(self, job_id: str) -> SparkJob:
7577
return self.job_by_id[job_id]
7678

7779

78-
job_cache = JobCache()
80+
global_job_cache = JobCache()
81+
82+
83+
def reset_job_cache():
84+
global global_job_cache
85+
global_job_cache = JobCache()
7986

8087

8188
def _find_free_port():
@@ -293,7 +300,7 @@ def historical_feature_retrieval(
293300
self.spark_submit(job_params),
294301
job_params.get_destination_path(),
295302
)
296-
job_cache.add_job(job)
303+
global_job_cache.add_job(job)
297304
return job
298305

299306
def offline_to_online_ingestion(
@@ -307,7 +314,7 @@ def offline_to_online_ingestion(
307314
self.spark_submit(ingestion_job_params, ui_port),
308315
ui_port,
309316
)
310-
job_cache.add_job(job)
317+
global_job_cache.add_job(job)
311318
return job
312319

313320
def start_stream_to_online_ingestion(
@@ -322,22 +329,22 @@ def start_stream_to_online_ingestion(
322329
ui_port,
323330
ingestion_job_params.get_job_hash(),
324331
)
325-
job_cache.add_job(job)
332+
global_job_cache.add_job(job)
326333
return job
327334

328335
def stage_dataframe(self, df, event_timestamp_column: str):
329336
raise NotImplementedError
330337

331338
def get_job_by_id(self, job_id: str) -> SparkJob:
332-
return job_cache.get_job_by_id(job_id)
339+
return global_job_cache.get_job_by_id(job_id)
333340

334341
def list_jobs(self, include_terminated: bool) -> List[SparkJob]:
335342
if include_terminated is True:
336-
return job_cache.list_jobs()
343+
return global_job_cache.list_jobs()
337344
else:
338345
return [
339346
job
340-
for job in job_cache.list_jobs()
347+
for job in global_job_cache.list_jobs()
341348
if job.get_status()
342349
in (SparkJobStatus.STARTING, SparkJobStatus.IN_PROGRESS)
343350
]

sdk/python/tests/test_streaming_control_loop.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
from feast.feature import Feature
1717
from feast.feature_table import FeatureTable
1818
from feast.job_service import ensure_stream_ingestion_jobs
19-
from feast.pyspark.launchers.standalone import StandaloneClusterLauncher
19+
from feast.pyspark.launchers.standalone import (
20+
StandaloneClusterLauncher,
21+
reset_job_cache,
22+
)
2023
from feast.value_type import ValueType
2124
from tests.feast_core_server import CoreServicer as MockCoreServicer
2225

@@ -37,7 +40,6 @@ def mock_server(servicer, add_fn):
3740
server.stop(None)
3841

3942

40-
CORE_URL = "core.feast.example.com"
4143
SERVING_URL = "serving.example.com"
4244

4345

@@ -101,6 +103,8 @@ def _delete_ft(self, client: Client):
101103
def test_streaming_job_control_loop(self) -> None:
102104
""" Test streaming job control loop logic. """
103105

106+
reset_job_cache()
107+
104108
core_servicer = MockCoreServicer()
105109

106110
processes: List[subprocess.Popen] = []

0 commit comments

Comments
 (0)