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
Merged

Conversation

@noamnelke
Copy link
Member

@noamnelke noamnelke commented Mar 20, 2019

No description provided.

@noamnelke noamnelke requested a review from zalmen Mar 20, 2019
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 Show resolved Hide resolved
return value, nil
}

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

This comment has been minimized.

@zalmen

zalmen Mar 25, 2019

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.

@noamnelke

noamnelke Mar 25, 2019
Author Member

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.

@noamnelke

noamnelke Mar 25, 2019
Author Member

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.

@zalmen

zalmen Mar 26, 2019

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

proving.go Show resolved Hide resolved
@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.

@zalmen

zalmen Mar 26, 2019

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.

@antonlerner

antonlerner Mar 26, 2019
Member

what if there are no layers?

This comment has been minimized.

@noamnelke

noamnelke Mar 26, 2019
Author Member

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 noamnelke merged commit 3651a54 into develop Mar 27, 2019
1 check passed
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
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants