-
Notifications
You must be signed in to change notification settings - Fork 818
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
Implement session expiry cleanup for persisted sessions #739
Implement session expiry cleanup for persisted sessions #739
Conversation
a2851ee
to
85dd80b
Compare
7d40949
to
cf36fd7
Compare
Hi @hylkevds may I ask you if you would like to be my buddy in this effort and provide a review to this functionality, please 🙏 ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just one concern about concurrency and one about re-activated sessions not being removed from the expiration queue.
} | ||
} | ||
|
||
private void trackForRemovalOnExpiration(ISessionsRepository.SessionData session) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we also need the opposite, unTrackForRemovalOnExpiration, for when a session is re-opened.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to implement it :)
cf36fd7
to
203edd4
Compare
c1acc2b
to
ad2bb43
Compare
} | ||
} | ||
|
||
private void trackForRemovalOnExpiration(ISessionsRepository.SessionData session) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to implement it :)
} | ||
|
||
private void untrackFromRemovalOnExpiration(ISessionsRepository.SessionData session) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs implementation...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String propertyValue = getProperty(propertyName); | ||
final char timeSpecifier = propertyValue.charAt(propertyValue.length() - 1); | ||
final TemporalUnit periodType; | ||
switch (timeSpecifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add seconds and minutes. In high-volume cases we don't want sessions to stay alive for more than a minute or so...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with e29ad31
While working on the subscription tree this weekend I noticed that subscriptions are not cleaned up when a session is cleaned up. This may need its own issue, WDYT? |
@hylkevds I think this could be a bug but:
the interceptor is notified only when an UNSUBSCRIBE message is received. When a clean session is wiped due to a disconnection it doesn't mean that the unsubscribe interceptor is notified, or do you thing it should? |
I think it should, yes. In our specific use-case there is no simple one-to-one mapping between events and the topics that may be interested in those events. It's an (in some cases extreme) many-to-many mapping. One event may have to be sent to potentially thousands of topics. That's why we need to keep track of exactly which topics actually have subscribers, so we can avoid generating messages for topics that have no subscriptions. Of course the subscription not being cleaned up and the interceptor not being notified are two distinct, but related, issues. |
@hylkevds please open an issue describing for that, describing the behavior. It will addressed in a separate PR. |
Hi @hylkevds I've addressed all your latest concerns. Please could you review it?! :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
…for non clean sessions
- made SessionData opaque of time using a Clock so that time can be easily managed in unit tests - spread the use of this Clock over interested classes and introduced test utilty class ForwardableClock - introduced delete method of session into Session's repository and used from the cleanup expired method.
…rsistent_client_expiration
…e cleanUp of removed sessions
…e expiry date and not now
e29ad31
to
410b145
Compare
Leverage the existing global expiry harness introduced with #739, reading the expiration time from the CONNECT's MQTT property SESSION_EXPIRY_INTERVAL.
Release notes
Implement the logic to expire the not clean sessions.
What does it do?
Track all expiration time after a session is closed or disconnects. Uses a delay queue to track the not clean session that expires and using a scheduled task, every second, check for the expired sessions and removes from the both SessionRegistry and also from the persistent store (SessionRepositoy).
Why it's important for the user?
This feature let the user to auto-purge the state of the not clean session after a certain amount of time configured at broker level in
moquette.conf
file through thepersistent_client_expiration
property which could have the format:<number><unit>
such as 1d for 1 day. Admitted values to unit ares
m
h
d
w
M
y
which respectively means seconds, minutes, hours, days, weeks, months and years. If not specified this global expiry defaults to INFINITE_EXPIRY which is ~80 years.