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

extract common cache with usability improvements #6

Merged
merged 14 commits into from Mar 27, 2019

Conversation

Projects
None yet
3 participants
@noamnelke
Copy link
Collaborator

noamnelke commented Mar 20, 2019

No description provided.

@noamnelke noamnelke requested a review from zalmen Mar 20, 2019

noamnelke added some commits Mar 24, 2019

Show resolved Hide resolved cache/cache.go Outdated
Show resolved Hide resolved cache/cache.go Outdated
Show resolved Hide resolved cache/cache.go
Show resolved Hide resolved cache/cache.go Outdated
Show resolved Hide resolved cache/cache.go Outdated
Show resolved Hide resolved cache/cache.go Outdated
Show resolved Hide resolved cache/layerfactories.go Outdated
return value, nil
}

func (s *SliceReadWriter) Write(p []byte) (n int, err error) {

This comment has been minimized.

Copy link
@zalmen

zalmen Mar 25, 2019

Member

I would expect that a method called "Write" will write to where position is pointing to, are you sure that the expected behavior is to append the data?

This comment has been minimized.

Copy link
@noamnelke

noamnelke Mar 25, 2019

Author Collaborator

This is a little confusing, I agree. Not sure how to fix it though.

Write is the Writer part, while the other methods are the Reader part. They are independent and position is only relevant to the Reader part. Write is append-only.

I'm not sure what's the best way to keep this behaviour and also make it clear to an uninformed user. If I change the function name to Append that would break the io.Writer interface implementation, but maybe that's the best solution. WDYT?

This comment has been minimized.

Copy link
@noamnelke

noamnelke Mar 25, 2019

Author Collaborator

I wouldn't be the first to have a combined read-writer that actually work independently. See go's bufio.ReadWriter -- its reader and writer work in isolation and don't share the position with each other.

I'm leaving as-is, unless you tell me otherwise.

This comment has been minimized.

Copy link
@zalmen

zalmen Mar 26, 2019

Member

Rename Write to Append and add a comment next to Seek saying that it only effects the reader

Show resolved Hide resolved proving.go

noamnelke added some commits Mar 25, 2019

@noamnelke noamnelke requested a review from zalmen Mar 25, 2019

return value, nil
}

func (s *SliceReadWriter) Write(p []byte) (n int, err error) {

This comment has been minimized.

Copy link
@zalmen

zalmen Mar 26, 2019

Member

Rename Write to Append and add a comment next to Seek saying that it only effects the reader

}

func (c *Cache) LeafReader() LayerReadWriter {
return c.layers[0]

This comment has been minimized.

Copy link
@antonlerner

antonlerner Mar 26, 2019

Member

what if there are no layers?

This comment has been minimized.

Copy link
@noamnelke

noamnelke Mar 26, 2019

Author Collaborator

This method doesn't exist anymore, but there's:

func (c *Reader) GetLayerReader(layerHeight uint) LayerReader {
	return c.layers[layerHeight]
}

So the answer is that the layers map is initialized in the constructor and requesting a non-existent layer is a legit scenario that happens normally. If you try to read from a map with a key that doesn't exist you get the zero value, nil in this case.

noamnelke added some commits Mar 26, 2019

@noamnelke noamnelke merged commit 3651a54 into develop Mar 27, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@noamnelke noamnelke deleted the cache_object branch Mar 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.