-
Notifications
You must be signed in to change notification settings - Fork 12
Set current_file when reading osiris log #200
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
base: main
Are you sure you want to change the base?
Conversation
src/osiris_log.erl
Outdated
| readers_counter_fun = CountersFun, | ||
| shared = Shared | ||
| }, | ||
| current_file = File, |
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.
#osiris_log.current_file should be the relative path of the file in the #osiris_log.cfg#cfg.directory but init_data_reader_at/4 and open_offset_reader_at/4 are passed absolute paths to the segment file. These paths also happen to be binaries rather than lists since list_dir/1 converts the filenames to binaries and the paths passed to this function are derived from the index file names.
We need the field to always be a binary or always be a list so that this check works properly:
Lines 2986 to 2987 in 82ef2fd
| SegFile = make_file_name(NextChId, "segment"), | |
| case SegFile == CurFile of |
I think that always using binaries in #osiris_log.current_file would be nice just since binaries are more compact than list strings. I'm pretty sure we would only need to change make_file_name/2 to use iolist_to_binary/1 instead of lists:flatten/1:
Lines 2713 to 2715 in 82ef2fd
| make_file_name(N, Suff) -> | |
| lists:flatten( | |
| io_lib:format("~20..0B.~s", [N, Suff])). |
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 did not change the make_file_name function as you suggest. I just set current_file the same way it is done in the other parts of the code that uses filename:basename(SegmentFile).
test/osiris_SUITE.erl
Outdated
| replica_nodes => []}, | ||
| {ok, #{leader_pid := Leader}} = osiris:start_cluster(Conf0), | ||
| {ok, Log0} = osiris:init_reader(Leader, next, {offset_reader_1, []}), | ||
| ?assertNot(undefined =:= osiris_log:get_current_file(Log0)). |
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 like the dialyzer isn't happy about this check since get_current_file/1's spec says that it can never return undefined. Since we're opening this on an empty log we could check this instead:
| ?assertNot(undefined =:= osiris_log:get_current_file(Log0)). | |
| ?assertEqual(<<"00000000000000000000.segment">>, | |
| osiris_log:get_current_file(Log0)). |
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.
Thank you @the-mikedavis for reviewing the PR!
Removed spaces Used same function to extract the relative path used in other parts of the code Fixed the assertion as the function indeed never reuturns undefined
It looks as if the
current_filefield of theosiris_logrecord is not updated when the log is opened to read from it.I have noticed it while implementing the stream browser. I wanted to show the segment file associated to a group of chunks and messages.