la_mojo: close day report at local midnight and open the next day's #9

Merged
ClaudeAI merged 1 commits from fix/report-day-rollover into master 2 hours ago
ClaudeAI commented 3 hours ago
Collaborator

Summary

At local midnight, the open day report (data/reports/YYYY/MM/DD/report.db, plus the pictures and videos stored next to it) is now closed, and the next day's report directory is opened.

Root cause

The only code that moved the report to a new day sat in the SESSION_START branch of sqliteDBC::updateStats(), and that branch never ran: updateStats() starts with if (m_bStaIsConnected && (evt || video)), but session status changes are reported as updateStats(false, false, SESSION_xxx). So the report only changed day when the process restarted, and everything after midnight went into the previous day's report.

Changes

  • mojoKernel::handleDayChange() (called every second from validateReports()), at local midnight:
    1. Closes an open session that started on the previous day, so its END event goes into the old report. The next event starts a new session in the new day.
    2. If a video segment with events is still recording, waits for it first, at most DAY_CHANGE_MAX_VIDEO_WAIT (90 s), so the video is stored next to its events.
    3. Once the END event is written, switches the report to the new day. If there is no open session, it switches immediately.
  • sqliteDBC::switchReportToCurrentDay() / openDayReport(): opens or creates the current local day's directory and database, and retries if that fails. The report state is protected by a recursive mutex, because the switch runs on the kernel thread while events are written on the event thread.
  • updateStats(): session status changes are no longer filtered out, so the session counters in stat.db (days.session_count / session_closed) are now actually updated, and SESSION_START also switches the report when needed.

Testing

Test programs built around the real sqliteDBC code, run under faketime starting at 23:59:57-58 in Asia/Jerusalem:

  • Concurrent writes: a thread writing events every 2 ms while switching across midnight. 1,254 events stored, none lost. All events after the switch are in the 27th's report. 3 events stamped 00:00:00 went into the 26th's report because they were written in the moment between midnight and the switch call (up to 1 s in the kernel). Also run under ThreadSanitizer and AddressSanitizer with no findings.
  • Session across midnight: START and TARGET at 23:59:58, END at 00:00:01. All three end up in the 26th's report. After the switch, new events and the new session go to the 27th's. stat.db shows 26th: 1 session, closed; 27th: 1 session, open.
  • No kernel switch: a new session starting after midnight moves the report by itself.
  • Compiles with the Debug86 flags with no new warnings. The full program wasn't run.

Generated with Claude Code

https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16

## Summary At local midnight, the open day report (`data/reports/YYYY/MM/DD/report.db`, plus the pictures and videos stored next to it) is now closed, and the next day's report directory is opened. ### Root cause The only code that moved the report to a new day sat in the `SESSION_START` branch of `sqliteDBC::updateStats()`, and that branch never ran: `updateStats()` starts with `if (m_bStaIsConnected && (evt || video))`, but session status changes are reported as `updateStats(false, false, SESSION_xxx)`. So the report only changed day when the process restarted, and everything after midnight went into the previous day's report. ### Changes - **`mojoKernel::handleDayChange()`** (called every second from `validateReports()`), at local midnight: 1. Closes an open session that started on the previous day, so its END event goes into the old report. The next event starts a new session in the new day. 2. If a video segment with events is still recording, waits for it first, at most `DAY_CHANGE_MAX_VIDEO_WAIT` (90 s), so the video is stored next to its events. 3. Once the END event is written, switches the report to the new day. If there is no open session, it switches immediately. - **`sqliteDBC::switchReportToCurrentDay()` / `openDayReport()`:** opens or creates the current local day's directory and database, and retries if that fails. The report state is protected by a recursive mutex, because the switch runs on the kernel thread while events are written on the event thread. - **`updateStats()`:** session status changes are no longer filtered out, so the session counters in `stat.db` (`days.session_count` / `session_closed`) are now actually updated, and `SESSION_START` also switches the report when needed. ## Testing Test programs built around the real `sqliteDBC` code, run under `faketime` starting at 23:59:57-58 in Asia/Jerusalem: - **Concurrent writes:** a thread writing events every 2 ms while switching across midnight. 1,254 events stored, none lost. All events after the switch are in the 27th's report. 3 events stamped 00:00:00 went into the 26th's report because they were written in the moment between midnight and the switch call (up to 1 s in the kernel). Also run under ThreadSanitizer and AddressSanitizer with no findings. - **Session across midnight:** START and TARGET at 23:59:58, END at 00:00:01. All three end up in the 26th's report. After the switch, new events and the new session go to the 27th's. `stat.db` shows 26th: 1 session, closed; 27th: 1 session, open. - **No kernel switch:** a new session starting after midnight moves the report by itself. - Compiles with the `Debug86` flags with no new warnings. The full program wasn't run. Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
ClaudeAI added 1 commit 3 hours ago
cfa1a852a7
la_mojo: close the day report at local midnight and open the next day's
ClaudeAI merged commit 495e21b49b into master 2 hours ago
The pull request has been merged as 495e21b49b.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.