Skip to content

Commit 65e7f08

Browse files
committed
Revert "start using datetimes with fractional seconds with mysql"
This reverts commit 8a07c58.
1 parent d6fc9e2 commit 65e7f08

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

mlos_bench/mlos_bench/storage/sql/experiment.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,11 @@ def _new_trial(
367367
ts_start: datetime | None = None,
368368
config: dict[str, Any] | None = None,
369369
) -> Storage.Trial:
370-
ts_start = utcify_timestamp(ts_start or datetime.now(UTC), origin="local")
370+
# MySQL can round microseconds into the future causing scheduler to skip trials.
371+
# Truncate microseconds to avoid this issue.
372+
ts_start = utcify_timestamp(ts_start or datetime.now(UTC), origin="local").replace(
373+
microsecond=0
374+
)
371375
_LOG.debug("Create trial: %s:%d @ %s", self._experiment_id, self._trial_id, ts_start)
372376
with self._engine.begin() as conn:
373377
try:

mlos_bench/mlos_bench/storage/sql/schema.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
create_mock_engine,
4040
inspect,
4141
)
42-
from sqlalchemy.dialects import mysql
4342
from sqlalchemy.engine import Engine
4443

4544
from mlos_bench.util import path_join
@@ -105,8 +104,8 @@ def __init__(self, engine: Engine | None):
105104
Column("git_repo", String(1024), nullable=False),
106105
Column("git_commit", String(40), nullable=False),
107106
# For backwards compatibility, we allow NULL for ts_start.
108-
Column("ts_start", DateTime().with_variant(mysql.DATETIME(fsp=6), "mysql")),
109-
Column("ts_end", DateTime().with_variant(mysql.DATETIME(fsp=6), "mysql")),
107+
Column("ts_start", DateTime),
108+
Column("ts_end", DateTime),
110109
# Should match the text IDs of `mlos_bench.environments.Status` enum:
111110
# For backwards compatibility, we allow NULL for status.
112111
Column("status", String(self._STATUS_LEN)),
@@ -180,16 +179,8 @@ def __init__(self, engine: Engine | None):
180179
Column("trial_id", Integer, nullable=False),
181180
Column("config_id", Integer, nullable=False),
182181
Column("trial_runner_id", Integer, nullable=True, default=None),
183-
Column(
184-
"ts_start",
185-
DateTime().with_variant(mysql.DATETIME(fsp=6), "mysql"),
186-
nullable=False,
187-
),
188-
Column(
189-
"ts_end",
190-
DateTime().with_variant(mysql.DATETIME(fsp=6), "mysql"),
191-
nullable=True,
192-
),
182+
Column("ts_start", DateTime, nullable=False),
183+
Column("ts_end", DateTime),
193184
# Should match the text IDs of `mlos_bench.environments.Status` enum:
194185
Column("status", String(self._STATUS_LEN), nullable=False),
195186
PrimaryKeyConstraint("exp_id", "trial_id"),
@@ -241,12 +232,7 @@ def __init__(self, engine: Engine | None):
241232
self._meta,
242233
Column("exp_id", String(self._ID_LEN), nullable=False),
243234
Column("trial_id", Integer, nullable=False),
244-
Column(
245-
"ts",
246-
DateTime(timezone=True).with_variant(mysql.DATETIME(fsp=6), "mysql"),
247-
nullable=False,
248-
default="now",
249-
),
235+
Column("ts", DateTime(timezone=True), nullable=False, default="now"),
250236
Column("status", String(self._STATUS_LEN), nullable=False),
251237
UniqueConstraint("exp_id", "trial_id", "ts"),
252238
ForeignKeyConstraint(
@@ -281,12 +267,7 @@ def __init__(self, engine: Engine | None):
281267
self._meta,
282268
Column("exp_id", String(self._ID_LEN), nullable=False),
283269
Column("trial_id", Integer, nullable=False),
284-
Column(
285-
"ts",
286-
DateTime(timezone=True).with_variant(mysql.DATETIME(fsp=6), "mysql"),
287-
nullable=False,
288-
default="now",
289-
),
270+
Column("ts", DateTime(timezone=True), nullable=False, default="now"),
290271
Column("metric_id", String(self._ID_LEN), nullable=False),
291272
Column("metric_value", String(self._METRIC_VALUE_LEN)),
292273
UniqueConstraint("exp_id", "trial_id", "ts", "metric_id"),

0 commit comments

Comments
 (0)