Skip to content

Commit 8a07c58

Browse files
committed
start using datetimes with fractional seconds with mysql
1 parent ed89170 commit 8a07c58

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

mlos_bench/mlos_bench/storage/sql/experiment.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,7 @@ def _new_trial(
367367
ts_start: datetime | None = None,
368368
config: dict[str, Any] | None = None,
369369
) -> Storage.Trial:
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-
)
370+
ts_start = utcify_timestamp(ts_start or datetime.now(UTC), origin="local")
375371
_LOG.debug("Create trial: %s:%d @ %s", self._experiment_id, self._trial_id, ts_start)
376372
with self._engine.begin() as conn:
377373
try:

mlos_bench/mlos_bench/storage/sql/schema.py

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

4445
from mlos_bench.util import path_join
@@ -104,8 +105,8 @@ def __init__(self, engine: Engine | None):
104105
Column("git_repo", String(1024), nullable=False),
105106
Column("git_commit", String(40), nullable=False),
106107
# For backwards compatibility, we allow NULL for ts_start.
107-
Column("ts_start", DateTime),
108-
Column("ts_end", DateTime),
108+
Column("ts_start", DateTime().with_variant(mysql.DATETIME(fsp=6), "mysql")),
109+
Column("ts_end", DateTime().with_variant(mysql.DATETIME(fsp=6), "mysql")),
109110
# Should match the text IDs of `mlos_bench.environments.Status` enum:
110111
# For backwards compatibility, we allow NULL for status.
111112
Column("status", String(self._STATUS_LEN)),
@@ -179,8 +180,16 @@ def __init__(self, engine: Engine | None):
179180
Column("trial_id", Integer, nullable=False),
180181
Column("config_id", Integer, nullable=False),
181182
Column("trial_runner_id", Integer, nullable=True, default=None),
182-
Column("ts_start", DateTime, nullable=False),
183-
Column("ts_end", DateTime),
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+
),
184193
# Should match the text IDs of `mlos_bench.environments.Status` enum:
185194
Column("status", String(self._STATUS_LEN), nullable=False),
186195
PrimaryKeyConstraint("exp_id", "trial_id"),
@@ -232,7 +241,12 @@ def __init__(self, engine: Engine | None):
232241
self._meta,
233242
Column("exp_id", String(self._ID_LEN), nullable=False),
234243
Column("trial_id", Integer, nullable=False),
235-
Column("ts", DateTime(timezone=True), nullable=False, default="now"),
244+
Column(
245+
"ts",
246+
DateTime(timezone=True).with_variant(mysql.DATETIME(fsp=6), "mysql"),
247+
nullable=False,
248+
default="now",
249+
),
236250
Column("status", String(self._STATUS_LEN), nullable=False),
237251
UniqueConstraint("exp_id", "trial_id", "ts"),
238252
ForeignKeyConstraint(
@@ -267,7 +281,12 @@ def __init__(self, engine: Engine | None):
267281
self._meta,
268282
Column("exp_id", String(self._ID_LEN), nullable=False),
269283
Column("trial_id", Integer, nullable=False),
270-
Column("ts", DateTime(timezone=True), nullable=False, default="now"),
284+
Column(
285+
"ts",
286+
DateTime(timezone=True).with_variant(mysql.DATETIME(fsp=6), "mysql"),
287+
nullable=False,
288+
default="now",
289+
),
271290
Column("metric_id", String(self._ID_LEN), nullable=False),
272291
Column("metric_value", String(self._METRIC_VALUE_LEN)),
273292
UniqueConstraint("exp_id", "trial_id", "ts", "metric_id"),

0 commit comments

Comments
 (0)