diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2019-12-19 14:50:19 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2019-12-19 14:50:19 +0300 |
commit | 94123f0d9ca4c0227d509fb970498de6752e2cb0 (patch) | |
tree | c496a97980ec417768d6a382ee25b3353e7fc938 | |
parent | 846cee2f323dbc6eb8e21eeef1aa17dbadb6648e (diff) | |
parent | 70d39d9c3af69aa3e419fe84f5599c4e2e795316 (diff) |
Merge branch 'po-revert-cache-invalidator-ff-remove' into 'master'
Add back feature flag for cache invalidation
See merge request gitlab-org/gitaly!1706
-rw-r--r-- | changelogs/unreleased/po-revert-cache-invalidator-ff-remove.yml | 5 | ||||
-rw-r--r-- | internal/metadata/featureflag/feature_flags.go | 4 | ||||
-rw-r--r-- | internal/middleware/cache/cache.go | 7 | ||||
-rw-r--r-- | internal/middleware/cache/cache_test.go | 3 | ||||
-rw-r--r-- | internal/service/smarthttp/cache.go | 1 | ||||
-rw-r--r-- | internal/service/smarthttp/inforefs_test.go | 1 |
6 files changed, 19 insertions, 2 deletions
diff --git a/changelogs/unreleased/po-revert-cache-invalidator-ff-remove.yml b/changelogs/unreleased/po-revert-cache-invalidator-ff-remove.yml new file mode 100644 index 000000000..cfae2aed6 --- /dev/null +++ b/changelogs/unreleased/po-revert-cache-invalidator-ff-remove.yml @@ -0,0 +1,5 @@ +--- +title: Add back feature flag for cache invalidation +merge_request: 1706 +author: +type: fixed diff --git a/internal/metadata/featureflag/feature_flags.go b/internal/metadata/featureflag/feature_flags.go index d64c00909..bc02a67af 100644 --- a/internal/metadata/featureflag/feature_flags.go +++ b/internal/metadata/featureflag/feature_flags.go @@ -10,6 +10,10 @@ const ( LinguistFileCountStats = "linguist_file_count_stats" // HooksRPC will invoke update, pre receive, and post receive hooks by using RPCs HooksRPC = "hooks_rpc" + // CacheInvalidator controls the tracking of repo state via gRPC + // annotations (i.e. accessor and mutator RPC's). This enables cache + // invalidation by changing state when the repo is modified. + CacheInvalidator = "cache-invalidator" ) const ( diff --git a/internal/middleware/cache/cache.go b/internal/middleware/cache/cache.go index da5cd07c8..0a3415ed5 100644 --- a/internal/middleware/cache/cache.go +++ b/internal/middleware/cache/cache.go @@ -9,6 +9,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/sirupsen/logrus" diskcache "gitlab.com/gitlab-org/gitaly/internal/cache" + "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc" @@ -37,7 +38,8 @@ func shouldIgnore(fullMethod string) bool { // repository in a gRPC stream based RPC func StreamInvalidator(ci Invalidator, reg *protoregistry.Registry) grpc.StreamServerInterceptor { return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { - if shouldIgnore(info.FullMethod) { + if !featureflag.IsEnabled(ss.Context(), featureflag.CacheInvalidator) || + shouldIgnore(info.FullMethod) { return handler(srv, ss) } @@ -64,7 +66,8 @@ func StreamInvalidator(ci Invalidator, reg *protoregistry.Registry) grpc.StreamS // repository in a gRPC unary RPC func UnaryInvalidator(ci Invalidator, reg *protoregistry.Registry) grpc.UnaryServerInterceptor { return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) { - if shouldIgnore(info.FullMethod) { + if !featureflag.IsEnabled(ctx, featureflag.CacheInvalidator) || + shouldIgnore(info.FullMethod) { return handler(ctx, req) } diff --git a/internal/middleware/cache/cache_test.go b/internal/middleware/cache/cache_test.go index fa3aef4a4..b4aa56307 100644 --- a/internal/middleware/cache/cache_test.go +++ b/internal/middleware/cache/cache_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diskcache "gitlab.com/gitlab-org/gitaly/internal/cache" + "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/internal/middleware/cache" "gitlab.com/gitlab-org/gitaly/internal/middleware/cache/testdata" "gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry" @@ -45,6 +46,8 @@ func TestInvalidators(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() + ctx = featureflag.ContextWithFeatureFlag(ctx, featureflag.CacheInvalidator) + svc := &testSvc{} cli, cc, cleanup := newTestSvc(t, ctx, srvr, svc) diff --git a/internal/service/smarthttp/cache.go b/internal/service/smarthttp/cache.go index de3680fb9..7666c1af5 100644 --- a/internal/service/smarthttp/cache.go +++ b/internal/service/smarthttp/cache.go @@ -50,6 +50,7 @@ const UploadPackCacheFeatureFlagKey = "inforef-uploadpack-cache" func tryCache(ctx context.Context, in *gitalypb.InfoRefsRequest, w io.Writer, missFn func(io.Writer) error) error { if !featureflag.IsEnabled(ctx, UploadPackCacheFeatureFlagKey) || + !featureflag.IsEnabled(ctx, featureflag.CacheInvalidator) || len(in.GetGitConfigOptions()) > 0 || len(in.GetGitProtocol()) > 0 { return missFn(w) diff --git a/internal/service/smarthttp/inforefs_test.go b/internal/service/smarthttp/inforefs_test.go index 441ec59ab..9cbb1fcaa 100644 --- a/internal/service/smarthttp/inforefs_test.go +++ b/internal/service/smarthttp/inforefs_test.go @@ -342,6 +342,7 @@ func replaceCachedResponse(t testing.TB, req *gitalypb.InfoRefsRequest, newConte func enableCacheFeatureFlag(ctx context.Context) context.Context { return metadata.NewOutgoingContext(ctx, metadata.New(map[string]string{ featureflag.HeaderKey(UploadPackCacheFeatureFlagKey): "true", + featureflag.HeaderKey(featureflag.CacheInvalidator): "true", })) } |