|
2 | 2 | import os |
3 | 3 | import argparse |
4 | 4 | import boto3 |
| 5 | +import json |
5 | 6 | import pickle |
6 | 7 | import gzip |
7 | 8 | import gc |
@@ -52,6 +53,29 @@ def _stage_log(stage: str, *, extra: str = "") -> None: |
52 | 53 | suffix = f" {extra}" if extra else "" |
53 | 54 | Logger.info(f"[TITANS/{PROVIDER}] {stage} rss_mb={_rss_mb():.1f}{suffix}") |
54 | 55 |
|
| 56 | + |
| 57 | +def _queue_compaction_request( |
| 58 | + request_path: str, |
| 59 | + *, |
| 60 | + hot_key: str, |
| 61 | + timestamp: datetime, |
| 62 | + timeout_seconds: float, |
| 63 | +) -> None: |
| 64 | + """Persist a compaction request for the shell to run in a fresh process.""" |
| 65 | + request_file = Path(request_path) |
| 66 | + request_file.parent.mkdir(parents=True, exist_ok=True) |
| 67 | + request_file.write_text( |
| 68 | + json.dumps( |
| 69 | + { |
| 70 | + "provider": PROVIDER, |
| 71 | + "hot_key": hot_key, |
| 72 | + "timestamp": timestamp.isoformat(), |
| 73 | + "timeout_seconds": timeout_seconds, |
| 74 | + } |
| 75 | + ), |
| 76 | + encoding="utf-8", |
| 77 | + ) |
| 78 | + |
55 | 79 | def merge_if_saving_price_sps_df(price_saving_if_df, sps_df, az=True): |
56 | 80 | # Ensure join keys are present and types match |
57 | 81 | join_df = pd.merge(price_saving_if_df, sps_df, on=['InstanceTier', 'InstanceType', 'Region'], how='outer') |
@@ -469,13 +493,30 @@ def main(): |
469 | 493 | extra=f"elapsed_s={time.time() - hot_started:.2f} hot_key={hot_key}", |
470 | 494 | ) |
471 | 495 | if hot_key: |
472 | | - compact_started = time.time() |
473 | | - _stage_log("run_compaction start", extra=f"hot_key={hot_key}") |
474 | | - run_compaction(hot_key, ts_utc, provider=PROVIDER, timeout_seconds=30.0, s3_client=titans_s3) |
475 | | - _stage_log( |
476 | | - "run_compaction end", |
477 | | - extra=f"elapsed_s={time.time() - compact_started:.2f} hot_key={hot_key}", |
478 | | - ) |
| 496 | + request_path = os.environ.get("TITANS_COMPACTION_REQUEST_PATH", "").strip() |
| 497 | + if request_path: |
| 498 | + _stage_log( |
| 499 | + "run_compaction handoff start", |
| 500 | + extra=f"hot_key={hot_key} request_path={request_path}", |
| 501 | + ) |
| 502 | + _queue_compaction_request( |
| 503 | + request_path, |
| 504 | + hot_key=hot_key, |
| 505 | + timestamp=ts_utc, |
| 506 | + timeout_seconds=30.0, |
| 507 | + ) |
| 508 | + _stage_log( |
| 509 | + "run_compaction handoff end", |
| 510 | + extra=f"hot_key={hot_key} request_path={request_path}", |
| 511 | + ) |
| 512 | + else: |
| 513 | + compact_started = time.time() |
| 514 | + _stage_log("run_compaction start", extra=f"hot_key={hot_key}") |
| 515 | + run_compaction(hot_key, ts_utc, provider=PROVIDER, timeout_seconds=30.0, s3_client=titans_s3) |
| 516 | + _stage_log( |
| 517 | + "run_compaction end", |
| 518 | + extra=f"elapsed_s={time.time() - compact_started:.2f} hot_key={hot_key}", |
| 519 | + ) |
479 | 520 | _stage_log("success") |
480 | 521 | Logger.info(f"[TITANS/{PROVIDER}] Successfully uploaded") |
481 | 522 | else: |
|
0 commit comments