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

Improve encapsulation of shards #49

Merged
merged 4 commits into from Sep 25, 2017
Merged

Conversation

cristaloleg
Copy link
Collaborator

@cristaloleg cristaloleg commented Sep 21, 2017

  • Get, Set methods are moved from bigcache.go to shard.go
  • initNewShard has additional param clock
  • all locks logic exists only inside shard
  • get rid of copyCurrentShardMap
  • getIndex and oldest methods added to shard
  • introduced index variable in getShard

Next PR will introduce Shard interface, newShard method and additional changes.

@coveralls
Copy link

coveralls commented Sep 21, 2017

Coverage Status

Coverage decreased (-0.2%) to 98.77% when pulling 2cee00a on cristaloleg:master into aa76879 on allegro:master.

@coveralls
Copy link

coveralls commented Sep 21, 2017

Coverage Status

Coverage decreased (-0.1%) to 98.776% when pulling c58910b on cristaloleg:master into aa76879 on allegro:master.

@cristaloleg
Copy link
Collaborator Author

As before: coverage failure was introduced before.

Copy link
Collaborator

@janisz janisz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments on some minor issues with readability.

shard.go Outdated
s.lock.RLock()

var elements = make([]uint32, len(s.hashmap))
next := 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next is local variable and could be defined outside of critical section (before s.lock.RLock())

shard.go Outdated
return s.entries.Get(index)
}

func (s *cacheShard) copyKeys() ([]uint32, int) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return values of this function are not obvious (espsecialy second → next) can you add a godoc with information what is the result of this function.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it wasn't documented before. How about using named return parameters to defined what's returned?

func (s *cacheShard) copyKeys() (keyes []uint32, length int) {

bigcache.go Outdated
}
}

func (c *BigCache) getShard(hashedKey uint64) (shard *cacheShard) {
return c.shards[hashedKey&c.shardMask]
index := hashedKey & c.shardMask
return c.shards[index]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be left untouched.

shard.go Outdated
return s.entries.Peek()
}

func (s *cacheShard) getIndex(index int) ([]byte, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be renamed. When I see getIndex I think that this function will return an index. How about getEntryUnderIndex or just getEntry?

shard.go Outdated
s.lock.Unlock()
}

func (s *cacheShard) oldest() ([]byte, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about renaming to getOldestEntry? Below is a method with get... so we should follow one naming scheme and best if functions are named as a verb declaring what they are doing. I'm fine with a convention of naming function with a noun that they produce but then we need to rename all other functions.

@cristaloleg
Copy link
Collaborator Author

Thanks, will update tomorrow.
WDYT about creating a release on Github before big changes will be merged?

@janisz
Copy link
Collaborator

janisz commented Sep 23, 2017

Thanks for quick response. We haven't created any release so far. It's a good idea to start making releases changelog for users. IMO API is stable and we definitely want to keep backward compatibility so we can start with version 1.0.

@druminski What do you think?

@druminski
Copy link
Contributor

@janisz Yes, I do agree with you that the API is stable, beside that we don't have plans to do major changes. Therefore we can start release version 1.0. As for writing a changelog, imo it is a good idea.

@cristaloleg overall your PR looks good, although please apply @janisz suggestions

@cristaloleg
Copy link
Collaborator Author

@janisz @druminski I'll update PR later today, thank for the review.

@coveralls
Copy link

coveralls commented Sep 25, 2017

Coverage Status

Coverage decreased (-0.2%) to 98.77% when pulling 2d020b2 on cristaloleg:master into aa76879 on allegro:master.

@janisz
Copy link
Collaborator

janisz commented Sep 25, 2017

@cristaloleg LGTM. I'll create a release and merge it after.

@cristaloleg
Copy link
Collaborator Author

@janisz ok, as you wish.

@janisz janisz merged commit 7487d18 into allegro:master Sep 25, 2017
@janisz
Copy link
Collaborator

janisz commented Sep 25, 2017

Done. @cristaloleg Huge thanks for this refactoring.

@cristaloleg
Copy link
Collaborator Author

@janisz no problem, will push next PR in a few days.

@janisz janisz mentioned this pull request Oct 10, 2017
flisky pushed a commit to flisky/bigcache that referenced this pull request May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants