Skip to content

Commit

Permalink
remove prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 committed Nov 11, 2020
1 parent ba3afb6 commit 5a1c85a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 14 deletions.
6 changes: 1 addition & 5 deletions pkg/skaffold/build/cache/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
)

const (
storePrefix = "dependency_hash"
)

// For testing
var (
newArtifactHasherFunc = newArtifactHasher
Expand All @@ -65,7 +61,7 @@ func newArtifactHasher(artifacts build.ArtifactGraph, lister DependencyLister, m
artifacts: artifacts,
lister: lister,
mode: mode,
syncStore: util.NewSyncStore(storePrefix),
syncStore: util.NewSyncStore(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/docker/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

var (
dependencyCache = util.NewSyncStore("getDependencies")
dependencyCache = util.NewSyncStore()
)

// NormalizeDockerfilePath returns the absolute path to the dockerfile.
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/docker/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func TestGetDependenciesCached(t *testing.T) {
testutil.Run(t, test.description, func(t *testutil.T) {
t.Override(&RetrieveImage, test.retrieveImgMock)
t.Override(&util.OSEnviron, func() []string { return []string{} })
t.Override(&dependencyCache, util.NewSyncStore(test.description))
t.Override(&dependencyCache, util.NewSyncStore())

tmpDir := t.NewTempDir().Touch("server.go", "random.go")
tmpDir.Write("Dockerfile", copyServerGo)
Expand Down
7 changes: 2 additions & 5 deletions pkg/skaffold/util/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
// SyncStore exports a single method `Exec` to ensure single execution of a function
// and share the result between all callers of the function.
type SyncStore struct {
prefix string
sf singleflight.Group
results sync.Map
}
Expand All @@ -35,8 +34,7 @@ type SyncStore struct {
// If it's called multiple times for the same key only the first call will execute and store the result of f.
// All other calls will be blocked until the running instance of f returns and all of them receive the same result.
func (o *SyncStore) Exec(key string, f func() interface{}) interface{} {
fullKey := o.prefix + key
val, err := o.sf.Do(fullKey, func() (_ interface{}, err error) {
val, err := o.sf.Do(key, func() (_ interface{}, err error) {
// trap any runtime error due to synchronization issues.
defer func() {
if rErr := recover(); rErr != nil {
Expand All @@ -57,9 +55,8 @@ func (o *SyncStore) Exec(key string, f func() interface{}) interface{} {
}

// NewSyncStore returns a new instance of `SyncStore`
func NewSyncStore(prefixCacheKey string) *SyncStore {
func NewSyncStore() *SyncStore {
return &SyncStore{
prefix: prefixCacheKey,
sf: singleflight.Group{},
results: sync.Map{},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/skaffold/util/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestSyncStore(t *testing.T) {
var wg sync.WaitGroup
wg.Add(10)

s := NewSyncStore("test")
s := NewSyncStore()
for i := 0; i < 5; i++ {
for j := 0; j < 2; j++ {
go func(i int) {
Expand All @@ -59,7 +59,7 @@ func TestSyncStore(t *testing.T) {
})

testutil.Run(t, "test panic handled correctly", func(t *testutil.T) {
s := NewSyncStore("test-panic")
s := NewSyncStore()
val := s.Exec("panic", func() interface{} {
panic(fmt.Errorf("message"))
})
Expand Down

0 comments on commit 5a1c85a

Please sign in to comment.