Skip to content
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

Reader API #5

Closed
marceloboeira opened this issue May 27, 2019 · 6 comments
Closed

Reader API #5

marceloboeira opened this issue May 27, 2019 · 6 comments
Labels
help wanted Extra attention is needed
Milestone

Comments

@marceloboeira
Copy link
Owner

marceloboeira commented May 27, 2019

Right now, you need to know exactly the points you want to read in order to be able to read from a log, otherwise you get an error.

Considering that the commit_log API is pretty much a crate, we should handle all its public methods as public interface, so, it is essential that we improve that by having a wrapper "response" to improve the UX of the reader side…

Acceptance criteria

At the end of this task, we should be able to read messages through:

commit_log = …

let last_record = commit_log.read(Position::Horizon) // Horizon is the first entry available for the log

// The read can receive either an offset of horizon
let last_record = commit_log.read(Position::Offset(1000)).unwrap()!

// last record returns the content of the record as well as a reference to the next one, when available
 
last_record.record() // returns a stream of bytes …
last_record.next() // returns a Result<Record, io::Error> (it could be the last record, then we would return “EOF” error…)

// there could be options, such as:
last_position = last_record.record().position()...
commit_log.read_after(last_position, 10) // to read 10 records after the given position) 

This might envolve creating the Record struct, if it comes to that, let’s make sure we change Writing/Reading from the commit log to support that.

@marceloboeira marceloboeira added the help wanted Extra attention is needed label May 27, 2019
@marceloboeira marceloboeira changed the title CommitLog Read API Reader API May 27, 2019
@marceloboeira marceloboeira added this to the 0.1.0 milestone May 27, 2019
@cuichenli
Copy link
Contributor

Hi @marceloboeira, I would like to help on this issue, and would like to ensure I am not in the wrong direction. Following is my understanding, for this issue, you would like to implement one method read for commit_log, the read method would take in one parameter of Position structure and will return one instance of Record structure. Is that right? Thanks!

@marceloboeira
Copy link
Owner Author

@cuichenli Position is an Enum, where you can send Horizon or a specific offset.

pub fn read_at(&self, position, number_of_records) -> Result<Vec<Record>, io::Error>

max_number_of_records -> how many entries from the index/log should be read (max). If there are less than the specified number, return them...

And the commit_log::read(position) is basically just a syntax-sugar for read_at(position, 1).

something like:

pub fn read(&self, position) -> Result<Record, io::Error> {
   self.read_at(position, 1)?.[0]
}

You can start small, open the PR and we discuss further details.

@cuichenli
Copy link
Contributor

Hi, @marceloboeira I have made a simple draft pr #14 , hope I am not too wrong on it. I am new to Rust so I may have made a lot of mistakes as well, please kindly forgive.

@marceloboeira
Copy link
Owner Author

I had a quick look, seems great! I’ll double check later today and merge it 👌🏻

@cuichenli
Copy link
Contributor

@marceloboeira What should we do next for this issue? By now we have implemented the Record, Reader, and Position. 🤔

@marceloboeira
Copy link
Owner Author

I think we're good for now! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants