Skip to content

Clear sessions cache on transfer #5608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

zoldar
Copy link
Contributor

@zoldar zoldar commented Aug 4, 2025

Changes

This PR implements clearing session cache on complete transfer in order to avoid making the already transferred session stale. To further prevent this, both, session and event WriteBuffer processes are blocked for the duration of the transfer.

The feature is behind an ENV feature flag, CLICKHOUSE_SESSION_LOCK_ENABLED which defaults to false. Enabling it will require adjusting config on infra level.

Tests

  • Automated tests have been added

@zoldar zoldar force-pushed the clear-sessions-cache-on-transfer branch 2 times, most recently from 3efc072 to e056045 Compare August 4, 2025 16:59
@zoldar zoldar added the preview label Aug 5, 2025
Copy link

github-actions bot commented Aug 5, 2025

Preview environment👷🏼‍♀️🏗️
PR-5608

:pass
end
else
unlock(name)
Copy link
Contributor Author

@zoldar zoldar Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bit of a weak point here. The lock_timeout ensures the buildup of queues in write buffers is not too big. However, if transfer gets stuck for whatever reason or takes longer than the timeout, the writebuffers will resume processing events.

One way to go about this could be wiping cache here before unlock. I'm not sure, however, whether it won't break consistency of transferred cache if the wipe happens right in the middle of transfer. Likely not, as :ets.delete_all_objects is supposedly atomic, but I'm not 100% certain about how table dumping works with deletion in the middle of :ets.tab2list.

Copy link
Contributor Author

@zoldar zoldar Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed locking approach - we only need to lock Session.WriteBuffer for the duration of the transfer, no need to block both queues.

Also the session cache is wiped when the lock times out.


Process.flag(:trap_exit, true)
timer = Process.send_after(self(), :tick, flush_interval_ms)

^name = :ets.new(name, [:named_table, :set, :public])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need an ets table to hold the lock? would it be possible to keep it in the process state? No loop necessary either. Or am I reading this wrong?

Copy link
Contributor Author

@zoldar zoldar Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is, process state can only be accessed from within the process. While locking could be done with message passing, unlocking requires doing that outside the process queue which holds all the pending events to process stuck there for the duration of the lock. Unless you know some other way? 😅

@zoldar zoldar force-pushed the clear-sessions-cache-on-transfer branch from 239b348 to f6416b0 Compare August 6, 2025 09:44
@zoldar zoldar marked this pull request as ready for review August 6, 2025 13:50
@zoldar zoldar requested review from aerosol and a team August 6, 2025 13:50
@zoldar zoldar marked this pull request as draft August 8, 2025 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants