-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat(ds): move session data from mnesia
to emqx_ds
#12675
Open
thalesmg
wants to merge
6
commits into
emqx:master
Choose a base branch
from
thalesmg:ds-session-to-ds-m-20240306
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+964
−53
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3666e5f
feat(ds): move session data from `mnesia` to `emqx_ds`
thalesmg 5b31eff
feat(schema_hooks): introduce new API for union option injections
thalesmg ab20cae
test(ds): fix flaky test
thalesmg b8968f9
feat: allow defining fixed timestamp per message
thalesmg fe56326
test: use simpler cleanup
thalesmg f3d54c8
test: use better mocking decision
thalesmg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,13 +80,22 @@ namespace() -> | |
schema() -> | ||
[ | ||
{messages, | ||
ds_schema(#{ | ||
ds_schema(ref(builtin), 'durable_storage.messages', #{ | ||
default => | ||
#{ | ||
<<"backend">> => builtin | ||
}, | ||
importance => ?IMPORTANCE_MEDIUM, | ||
desc => ?DESC(messages) | ||
})}, | ||
{sessions, | ||
ds_schema(ref(builtin_session), 'durable_storage.sessions', #{ | ||
default => | ||
#{ | ||
<<"backend">> => builtin | ||
}, | ||
importance => ?IMPORTANCE_MEDIUM, | ||
desc => ?DESC(sessions) | ||
})} | ||
]. | ||
|
||
|
@@ -179,6 +188,19 @@ fields(builtin) -> | |
} | ||
)} | ||
]; | ||
fields(builtin_session) -> | ||
lists:map( | ||
fun | ||
({layout = Key, Sc0}) -> | ||
Override = #{type => hoconsc:union(builtin_layouts_session())}, | ||
{Key, hocon_schema:override(Sc0, Override)}; | ||
(Field) -> | ||
Field | ||
end, | ||
fields(builtin) | ||
); | ||
fields(layout_builtin_wildcard_optimized_session) -> | ||
fields(layout_builtin_wildcard_optimized); | ||
fields(builtin_local_write_buffer) -> | ||
[ | ||
{max_items, | ||
|
@@ -253,36 +275,50 @@ fields(layout_builtin_reference) -> | |
|
||
desc(builtin) -> | ||
?DESC(builtin); | ||
desc(builtin_session) -> | ||
?DESC(builtin); | ||
desc(builtin_local_write_buffer) -> | ||
?DESC(builtin_local_write_buffer); | ||
desc(layout_builtin_wildcard_optimized) -> | ||
?DESC(layout_builtin_wildcard_optimized); | ||
desc(layout_builtin_wildcard_optimized_session) -> | ||
?DESC(layout_builtin_wildcard_optimized); | ||
desc(_) -> | ||
undefined. | ||
|
||
%%================================================================================ | ||
%% Internal functions | ||
%%================================================================================ | ||
|
||
ds_schema(Options) -> | ||
ds_schema(MainRef, InjectionPoint, Options) -> | ||
sc( | ||
hoconsc:union([ | ||
ref(builtin) | ||
| emqx_schema_hooks:injection_point('durable_storage.backends', []) | ||
MainRef | ||
| emqx_schema_hooks:union_option_injections(InjectionPoint, []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This addresses this comment: https://github.com/emqx/emqx-platform/pull/135#discussion_r1514765105 |
||
]), | ||
Options | ||
). | ||
|
||
-ifndef(TEST). | ||
builtin_layouts() -> | ||
[ref(layout_builtin_wildcard_optimized)]. | ||
|
||
builtin_layouts_session() -> | ||
[ref(layout_builtin_wildcard_optimized_session)]. | ||
-else. | ||
builtin_layouts() -> | ||
%% Reference layout stores everything in one stream, so it's not | ||
%% suitable for production use. However, it's very simple and | ||
%% produces a very predictabale replay order, which can be useful | ||
%% for testing and debugging: | ||
[ref(layout_builtin_wildcard_optimized), ref(layout_builtin_reference)]. | ||
|
||
builtin_layouts_session() -> | ||
%% Reference layout stores everything in one stream, so it's not | ||
%% suitable for production use. However, it's very simple and | ||
%% produces a very predictabale replay order, which can be useful | ||
%% for testing and debugging: | ||
[ref(layout_builtin_wildcard_optimized_session), ref(layout_builtin_reference)]. | ||
-endif. | ||
|
||
sc(Type, Meta) -> hoconsc:mk(Type, Meta). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This sounds weird, though I have to admit I haven't yet finished reviewing.
I think that read failure should not be equivalent to having no session record. Is there any good reason to do that?
On the test code: wouldn't it be simpler to match on
DB
and simulate failure only for the message DB? Current test code looks both super-hacky and extemely fragile.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.
Just that I'm not sure how we should handle (recoverable) failures in this case. 🤔
Sleep and retry?
Sounds like a much better idea, I'll fix 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.
Good question. This warrants some discussion but as a safe bet I'd propagate this failure to the client, and let them decide if they want to retry.
Also wondering what would happen now if locking is unavailable in a mria transaction, probably something effectively similar?
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.
This comes from
get_streams
being lenient with failures, so it could affect other portions of the code as well.Not sure I understand the question, but indeed not having transactions will lead to potential inconsistencies (at least in the builtin backend; FDB could avoid them, at least if deletions are not involved).
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.
Oh I see now. TBH this is (again) feels like a hack: we probably don't want to hide failures on that level.
I mean, I'm trying to understand what would happen to the client which is trying to open an existing session when current storage (mria) is unavailable.
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.
Good question, not sure on the exact answer. Since it uses dirty reads and writes, my guess is that it'll work with the local copy of the data (maybe hang in replicants while they can't RPC a core). 🤔
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.
Changed the test code to match on the DB.