Repository navigation
Fix duplicate table dataset rows in recorder - #4164
Conversation
TableDataSet.data returns its live, append-only rows list. The recorders stored it by reference on every collection, so all stored blocks aliased the same list, and even with a copy each collection re-recorded the full table (1+2+...+n rows with wrong timestamps). BaseDataRecorder now takes a snapshot via _take_snapshot(): for a TableDataSet it returns a new list holding only the rows added since the previous collection (re-including the replaced block's rows on an overwrite). Row dicts are shared with the dataset rather than copied, since neither the dataset nor the recorders mutate them; the TableDataSet.data docstring documents this. Other datasets are unchanged. Adds a regression test across DataRecorder, JSONDataRecorder, ParquetDataRecorder and SQLDataRecorder. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RbrUQUQAArrpH7rYQFt6KW
64710c0 to
c2daa1d
Compare
|
Thanks for the detailed feedback. I am starting to wonder whether going down the cursor route is the right solution. At the moment, the main point of Regardless, I believe we should merge #4168 first. |
- Add TableDataSet.get_rows_since(index), so BaseDataRecorder only tracks the cursor and no longer imports TableDataSet. The recorder looks the method up on the dataset's type, so only dataset classes that define it qualify. - Document that window_size keeps the rows of the last N collections for a TableDataSet. - Add a test that adds rows on only some steps and runs twice. - Drop the dropna in the table test now that mesa#4168 is merged. - Import TableDataSet at the top of the test module. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RbrUQUQAArrpH7rYQFt6KW
I'd still favour the cursor, though I see the appeal. Recorders that write to disk would still need to track which rows they've already written, so stamping in It would also clash with the |
|
I have opened a separate issue for that bug #4185 |
Fair point and it indeed points towards using a cursor. |
Collecting again at an already recorded time (for example, the end of a run followed by collect()) made the next recording of that time an overwrite. The backends delete what is stored for that time on an overwrite, but the cursor only re-supplied rows from the latest collection, so rows were lost (e.g., run_for(2), collect(), run_for(1) dropped the t=2 row in DataRecorder, ParquetDataRecorder and SQLDataRecorder). Rows of an append-only dataset never change once added, so an overwrite has nothing to correct. The recorder now skips overwrites for such datasets and only records rows it has not recorded yet, tracked with a single forward-only counter per dataset. _is_append_only() holds the class-level get_rows_since check. Adds a regression test for the case above across all four recorders. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RbrUQUQAArrpH7rYQFt6KW
The time-change, run-end and manual collect() paths each decided whether to overwrite, took a snapshot and stored it. The rule that append-only datasets are never overwritten lived only in the first two; collect() did not need it because it never overwrites. Move these steps into _record_dataset(), used by all three paths. This changes no behavior today, but keeps the rule in one place: once collect() overwrites at an already recorded time (as mesa#4148 proposes), a table's recorded rows would otherwise be deleted at that time while the snapshot only holds the new rows. Adds a test that an overwrite never deletes the recorded rows of an append-only dataset, across all four recorders. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RbrUQUQAArrpH7rYQFt6KW
|
Thanks for the careful review, @codebreaker32. I've pushed changes covering all six points: 1. Rows lost when collecting again at an already recorded time (c61cee2, 3e055bf) The root cause is that the backends delete whatever is stored for a specific time stamp on an overwrite, while the cursor only re-supplied the rows from the latest collection. So in your example ( Rows of a All three collection paths (time change, end of run, and explicit calls to I added some additional tests including your example and a direct check that an overwrite never deletes recorded table rows. These tests are run across all four recorders. 2. Empty snapshots: fixed by #4168, now merged into this branch. I added the test you suggested: rows on only some steps, run twice. 3. 4.
The inconsistency of how 5. Coupling: 6. Nit: |
codebreaker32
left a comment
There was a problem hiding this comment.
Thanks, everything looks good!
EwoutH
left a comment
There was a problem hiding this comment.
Thanks, looks good. Tests pass locally for all four recorders.
This PR fixes a bug when recording
TableDataSet. ATableDataSetuses a list to store its rows. So, when taking a snapshot, it is mutable. Whenever, new rows are added, they show up in earlier snapshots. In addition, every snapshot handled the entire dataset, including rows seen before.This PR solves both problems in one go by adding a cursor to the recorder that tracks which rows have been seen in previous snapshots. This approach is adequate, because
TableDataSetcan only ever be expanded by adding new rows to it. Rows cannot be removed.Closes #3967