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

Cache commit on Graveler ref manager #4497

Merged
merged 4 commits into from
Nov 2, 2022
Merged

Conversation

nopcoder
Copy link
Contributor

Close #4422

@nopcoder nopcoder added the include-changelog PR description should be included in next release changelog label Oct 27, 2022
@nopcoder nopcoder requested a review from a team October 27, 2022 20:03
@nopcoder nopcoder self-assigned this Oct 27, 2022
Copy link
Contributor

@itaiad200 itaiad200 left a comment

Choose a reason for hiding this comment

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

Great tests! Only blocking comment regarding unfound commit

@@ -31,19 +31,24 @@ const (
DefaultRepositoryCacheSize = 1000
DefaultRepositoryCacheExpiry = 5 * time.Second
DefaultRepositoryCacheJitter = DefaultRepositoryCacheExpiry / 2

DefaultCommitCacheSize = 1000
DefaultCommitCacheExpiry = 5 * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's increase it to 30 seconds? It's immutable anyhow..

Comment on lines 104 to 116
// commits cache
commitCacheConfig := cfg.CommitCacheConfig
if commitCacheConfig == nil {
commitCacheConfig = &CacheConfig{
Size: DefaultCommitCacheSize,
Expiry: DefaultCommitCacheExpiry,
Jitter: DefaultCommitCacheJitter,
}
}
commitCache := cache.NoCache
if commitCacheConfig.Size > 0 {
commitCache = cache.NewCache(commitCacheConfig.Size, commitCacheConfig.Expiry, cache.NewJitterFn(commitCacheConfig.Jitter))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: Duplicated logic to shared location

@@ -456,23 +487,38 @@ func (m *KVManager) GetCommitByPrefix(ctx context.Context, repository *graveler.
}

func (m *KVManager) GetCommit(ctx context.Context, repository *graveler.RepositoryRecord, commitID graveler.CommitID) (*graveler.Commit, error) {
key := fmt.Sprintf("%s:%s", repository.RepositoryID, commitID)
v, err := m.repoCache.GetOrSet(key, func() (v interface{}, err error) {
return m.getCommitBatch(ctx, repository, commitID)
Copy link
Contributor

Choose a reason for hiding this comment

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

It won't cache NotFound commits. I can't remember if we expect this to happen a lot. The chances of a user pointing directly to a commit hash which wasn't created yet is not big. However, we accept refs which could be anything. If we currently check that main isn't a commit, I think we should avoid that constant call to the store.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that full commit ID for non existing is something that probably will not be part of any main flow. Anything short or resolved from branch or tag should be an existing commit.
So filling the cache with non existing commit for a case that a user/app try to identify if commit exits I assume it will be something I don't want to return answer from the last 30sec.
Keeping it this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will open an issue/pr to handle optimization of branch vs commit prefix.

@nopcoder nopcoder requested a review from itaiad200 November 1, 2022 08:03
ctx := context.Background()
mockStore.EXPECT().Get(ctx, []byte("graveler"), []byte("repos/repo1")).Times(times).Return(&kv.ValueWithPredicate{}, nil)
repoCacheConfig := &ref.RepositoryCacheConfig{
cacheConfig := &ref.CacheConfig{
Size: 100,
Expiry: 2 * time.Second,
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're going to sleep in tests, why not 20 milliseconds?

@nopcoder nopcoder force-pushed the feature/cache-commits branch from ee37ea5 to 7bf4ecf Compare November 2, 2022 09:22
@nopcoder nopcoder merged commit e997d02 into master Nov 2, 2022
@nopcoder nopcoder deleted the feature/cache-commits branch November 2, 2022 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
include-changelog PR description should be included in next release changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache Commits in Graveler
3 participants