Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Unified Diff: luci_config/appengine/gaeconfig/default.go

Issue 2576923003: Implement config service cache on top of datastore (Closed)
Patch Set: Relocated, fix, split integration test, rebase. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « luci_config/appengine/backend/datastore/ds_test.go ('k') | luci_config/appengine/gaeconfig/default_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: luci_config/appengine/gaeconfig/default.go
diff --git a/luci_config/appengine/gaeconfig/default.go b/luci_config/appengine/gaeconfig/default.go
index d128bad884fcf43abf6a0cf3378df8c137472525..4e7c98924925294cc08118a22893734b2ace5a15 100644
--- a/luci_config/appengine/gaeconfig/default.go
+++ b/luci_config/appengine/gaeconfig/default.go
@@ -12,6 +12,7 @@ import (
"time"
"github.com/luci/luci-go/common/config/impl/filesystem"
+ "github.com/luci/luci-go/luci_config/appengine/backend/datastore"
"github.com/luci/luci-go/luci_config/appengine/backend/memcache"
gaeformat "github.com/luci/luci-go/luci_config/appengine/format"
"github.com/luci/luci-go/luci_config/server/cfgclient/backend"
@@ -20,6 +21,7 @@ import (
"github.com/luci/luci-go/luci_config/server/cfgclient/backend/erroring"
"github.com/luci/luci-go/luci_config/server/cfgclient/backend/format"
"github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig"
+ "github.com/luci/luci-go/server/router"
"github.com/luci/gae/service/info"
@@ -34,6 +36,30 @@ var ErrNotConfigured = errors.New("config service URL is not set in settings")
// local dev appserver model. See New for details.
const devCfgDir = "devcfg"
+// InstallCacheCronHandler installs the configuration service datastore caching
+// cron handler. This must be installed, and an associated cron must be set up,
+// if datastore caching is enabled.
+//
+// The cron should be configured to hit the handler at:
+// /admin/config/cache/manager
+func InstallCacheCronHandler(r *router.Router, base router.MiddlewareChain) {
+ installCacheCronHandlerImpl(r, base, nil)
+}
+
+// Install our cache cron handler into the supplied Router.
+//
+// bf is a generator function used to get the primary (service) Backend to build
+// on top of. If nil, the "production" (one used by Use) Backend will be used.
+func installCacheCronHandlerImpl(r *router.Router, base router.MiddlewareChain, be backend.B) {
+ base = base.Extend(func(c *router.Context, next router.Handler) {
+ // Install our Backend into our Context.
+ c.Context = installConfigBackend(c.Context, mustFetchCachedSettings(c.Context), be, true)
+ next(c)
+ })
+
+ datastore.Cache.InstallCronRoute("/admin/config/cache/manager", r, base)
+}
+
// Use installs the default luci-config client.
//
// The client is configured to use luci-config URL specified in the settings,
@@ -56,10 +82,10 @@ const devCfgDir = "devcfg"
func Use(c context.Context) context.Context { return useImpl(c, nil) }
func useImpl(c context.Context, be backend.B) context.Context {
- return installConfigBackend(c, mustFetchCachedSettings(c), be)
+ return installConfigBackend(c, mustFetchCachedSettings(c), be, false)
}
-func installConfigBackend(c context.Context, s *Settings, be backend.B) context.Context {
+func installConfigBackend(c context.Context, s *Settings, be backend.B, dsCron bool) context.Context {
if be == nil {
// Non-testing, build a Backend.
be = getPrimaryBackend(c, s)
@@ -79,6 +105,26 @@ func installConfigBackend(c context.Context, s *Settings, be backend.B) context.
// Add a ProcCache, backed by memcache.
be = memcache.Backend(be, exp)
be = caching.ProcCache(be, exp)
+
+ // If our datastore cache is enabled, install a handler for refresh. This
+ // will be loaded by dsCache's "HandlerFunc".
+ if s.DatastoreCacheMode != dsCacheDisabled {
+ dsc := datastore.Config{
+ RefreshInterval: exp,
+ FailOpen: s.DatastoreCacheMode == dsCacheEnabled,
+ }
+
+ if !dsCron {
+ // For non-cron, install the datastore cache Backend.
+ be = dsc.Backend(be)
+ } else {
+ // For cron, do not install the datastore cache Backend. Instead,
+ // install a lasting Handler into the Context to be used for cache
+ // resolution. This is necessary since resolution calls will not be
+ // the result of an actual resolution command (e.g., cache.Get).
+ c = dsc.WithHandler(c, datastore.CronLoader(be), datastore.RPCDeadline)
+ }
+ }
}
c = backend.WithBackend(c, be)
« no previous file with comments | « luci_config/appengine/backend/datastore/ds_test.go ('k') | luci_config/appengine/gaeconfig/default_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698