This is an automated email from the ASF dual-hosted git repository.

ocket8888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new dc859edec1 Fix t3c cache to invalidate on version change (#6883)
dc859edec1 is described below

commit dc859edec129a3291ee589a98e7729a608f2b78b
Author: Robert O Butts <[email protected]>
AuthorDate: Fri Jul 15 11:01:02 2022 -0600

    Fix t3c cache to invalidate on version change (#6883)
---
 CHANGELOG.md                              |  1 +
 cache-config/t3c-request/config/config.go |  1 +
 cache-config/t3cutil/getdata.go           |  6 +++++-
 cache-config/t3cutil/getdatacfg.go        | 18 +++++++++++++++++-
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9e4a1be00f..83427545d8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -59,6 +59,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 - Correction where using the placeholder `__HOSTNAME__` in "unknown" files 
(others than the defaults ones), was being replaced by the full FQDN instead of 
the shot hostname.
 - [#6800](https://github.com/apache/trafficcontrol/issues/6800) Fixed 
incorrect error message for `/server/details` associated with query parameters.
 - [#6712](https://github.com/apache/trafficcontrol/issues/6712) - Fixed error 
when loading the Traffic Vault schema from `create_tables.sql` more than once.
+- [#6883](https://github.com/apache/trafficcontrol/issues/6883) Fix t3c cache 
to invalidate on version change
 - [#6834](https://github.com/apache/trafficcontrol/issues/6834) - In API 4.0, 
fixed `GET` for `/servers` to display all profiles irrespective of the index 
position. Also, replaced query param `profileId` with `profileName`.
 - [#6299](https://github.com/apache/trafficcontrol/issues/6299) User 
representations don't match
 - [#6896](https://github.com/apache/trafficcontrol/issues/6896) Fixed the 
`POST api/cachegroups/id/queue_updates` endpoint so that it doesn't give an 
internal server error anymore.
diff --git a/cache-config/t3c-request/config/config.go 
b/cache-config/t3c-request/config/config.go
index 34933cc5e9..779f1a8aab 100644
--- a/cache-config/t3c-request/config/config.go
+++ b/cache-config/t3c-request/config/config.go
@@ -162,6 +162,7 @@ func InitConfig(appVersion string, gitRevision string) 
(Cfg, error) {
                        TOURL:          toURLParsed,
                        RevalOnly:      *revalOnlyPtr,
                        TODisableProxy: *disableProxyPtr,
+                       T3CVersion:     gitRevision,
                },
                Version:     appVersion,
                GitRevision: gitRevision,
diff --git a/cache-config/t3cutil/getdata.go b/cache-config/t3cutil/getdata.go
index c8f31aca27..24574cba30 100644
--- a/cache-config/t3cutil/getdata.go
+++ b/cache-config/t3cutil/getdata.go
@@ -54,6 +54,10 @@ type TCCfg struct {
 
        // OldCfg is the previously fetched ConfigData, for 'config' requests. 
May be nil.
        OldCfg *ConfigData
+
+       // T3CVersion is the version of the t3c app ecosystem
+       // This value will be the same for any t3c app.
+       T3CVersion string
 }
 
 func GetDataFuncs() map[string]func(TCCfg, io.Writer) error {
@@ -254,7 +258,7 @@ func SetUpdateStatusCompat(cfg TCCfg, serverName 
tc.CacheName, configApply, reva
 
 // WriteConfig writes the Traffic Ops data necessary to generate config to 
output.
 func WriteConfig(cfg TCCfg, output io.Writer) error {
-       cfgData, err := GetConfigData(cfg.TOClient, cfg.TODisableProxy, 
cfg.CacheHostName, cfg.RevalOnly, cfg.OldCfg)
+       cfgData, err := GetConfigData(cfg.TOClient, cfg.TODisableProxy, 
cfg.CacheHostName, cfg.RevalOnly, cfg.OldCfg, cfg.T3CVersion)
        if err != nil {
                return errors.New("getting config data: " + err.Error())
        }
diff --git a/cache-config/t3cutil/getdatacfg.go 
b/cache-config/t3cutil/getdatacfg.go
index b9661490cd..33d680bc06 100644
--- a/cache-config/t3cutil/getdatacfg.go
+++ b/cache-config/t3cutil/getdatacfg.go
@@ -39,6 +39,10 @@ import (
 const TrafficOpsProxyParameterName = `tm.rev_proxy.url`
 
 type ConfigData struct {
+       // Version is the version of the application which created the config 
data,
+       // primarily used for cache invalidation.
+       Version string `json:"version"`
+
        // Servers must be all the servers from Traffic Ops. May include 
servers not on the current cdn.
        Servers []atscfg.Server `json:"servers,omitempty"`
 
@@ -173,15 +177,27 @@ func MakeReqMetaData(respHdr http.Header) ReqMetaData {
 //
 // The cacheHostName is the hostname of the cache to get config generation 
data for.
 //
+// The oldCfg is previous config data which was cached. May be nil, if the 
caller has no previous data.
+// If it exists and is usable, If-Modified-Since requests will be made and the 
cache re-used where possible.
+//
+// The version is a unique version of the application, which should change 
with any compatibility changes.
+// Old config with a different version than the current won't be used (though 
in the future, smarter compatibility could be added).
+//
 // The revalOnly arg is whether to only get data necessary to revalidate, 
versus all data necessary to generate cache config.
-func GetConfigData(toClient *toreq.TOClient, disableProxy bool, cacheHostName 
string, revalOnly bool, oldCfg *ConfigData) (*ConfigData, error) {
+func GetConfigData(toClient *toreq.TOClient, disableProxy bool, cacheHostName 
string, revalOnly bool, oldCfg *ConfigData, version string) (*ConfigData, 
error) {
        start := time.Now()
        defer func() { log.Infof("GetTOData took %v\n", time.Since(start)) }()
 
        toIPs := &sync.Map{} // each Traffic Ops request could get a different 
IP, so track them all
        toData := &ConfigData{}
+       toData.Version = version
        toData.MetaData.CacheHostName = cacheHostName
 
+       if oldCfg != nil && oldCfg.Version != toData.Version {
+               log.Infof("old config version '%s' doesn't match current 
version '%s', old config will not be used!\n", oldCfg.Version, toData.Version)
+               oldCfg = nil
+       }
+
        serverProfilesParams := &sync.Map{}         // 
map[atscfg.ProfileName][]tc.Parameter
        serverProfilesParamsMetaData := &sync.Map{} // 
map[atscfg.ProfileName]ReqMetaData
 

Reply via email to