Skip to content

Record has changed since last read in table study_system_attributes [mariadb] #6065

@jvrodrisan

Description

@jvrodrisan

Expected behavior

When running an optimization using NSGAII and VSBXCrossover, I expect it to run without database errors. The NSGAII initialization is as follows:

sampler = optuna.samplers.NSGAIISampler(
                population_size=150,
                mutation_prob=0.08, 
                crossover_prob=0.85,
                swapping_prob=0.5,
                seed=_seed,
                crossover=optuna.samplers.nsgaii.VSBXCrossover(eta=15),
                constraints_func=self.constraints_opti if self.constraints else None
)

and database configuration below:

storage = optuna.storages.RDBStorage(url=self.db_url, heartbeat_interval=80, grace_period=160,
                   failed_trial_callback=RetryFailedTrialCallback(max_retry=5))

Environment

  • Optuna version: 4.2.1
  • Python version: 3.13.3
  • OS: Linux-6.12.21-amd64-x86_64-with-glibc2.41 (Debian 12)

Error messages, stack traces, or logs

ile "/home/jyck/.pyenv/versions/miniforge3-latest/envs/py313/lib/python3.13/site-packages/pymysql/connections.py", line 1199, in read
    first_packet = self.connection._read_packet()
  File "/home/jyck/.pyenv/versions/miniforge3-latest/envs/py313/lib/python3.13/site-packages/pymysql/connections.py", line 775, in _read_packet
    packet.raise_for_error()
    ~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/jyck/.pyenv/versions/miniforge3-latest/envs/py313/lib/python3.13/site-packages/pymysql/protocol.py", line 219, in raise_for_error
    err.raise_mysql_exception(self._data)
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/home/jyck/.pyenv/versions/miniforge3-latest/envs/py313/lib/python3.13/site-packages/pymysql/err.py", line 150, in raise_mysql_exception
    raise errorclass(errno, errval)
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1020, "Record has changed since last read in table 'study_system_attributes'")
[SQL: UPDATE study_system_attributes SET value_json=%(value_json)s WHERE study_system_attributes.study_system_attribute_id = %(study_system_attributes_study_system_attribute_id)s]
[parameters: {'value_json': '[5, [837, 877, 888, 943, 710, 871, 880, 908, 936, 937, 953, 357, 346, 853, 856, 869, 890, 934, 720, 802, 538, 652, 815, 513, 673, 688, 826, 20, 833,  ... (439 characters truncated) ... 64, 462, 460, 454, 453, 450, 448, 444, 443, 439, 435, 433, 431, 430, 429, 428, 424, 423, 421, 418, 416, 413, 408, 407, 404, 403, 402, 398, 395, 392]]', 'study_system_attributes_study_system_attribute_id': 47167}]
(Background on this error at: https://sqlalche.me/e/20/e3q8)

Steps to reproduce

  1. Just run my optimization rutine on 20 different terminals locally, and after some trials (not spsecifics steps to reproduce), some of the executions stopped with the error message provided.

Additional context

I have tried to use the GRPC proxy, but the problem happens similarly, it is even more common under it. It seems that there is an update to the DB at the same record on multiple threads and one of them fails. Tried different configurations for retry errors and heartbeat/grace periods but the issue remains.

I am using mariadb locally, version: mariadb from 11.8.1-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using EditLine wrapper

I have also tried Optuna 4.3.0 but it raises another error with NSGAII which will raise once this is solved to not have crossed issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions