Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit 92a1428

Browse files
rawlinprob05c
andauthored
Fix atstccfg Delivery Service Server caching. (#4387) (#4389)
* Fix atstccfg deliveryserviceserver caching Fixses an inconsistent ORT bug with files, noticably parent.config, not having all lines. Bug was filtering before saving the cache file. DSS gets everything, and then filters. It was filtering before saving the cache file, causing subsequent ORT calls under the cache age which had more DSSes to be missing them. This fixes it to filter after saving/loading the cache file, instead of before. * Add ORT use_cache arg, default true. Adds a use_cache argument to ORT (default true) to allow callers to tell atstccfg to not use the cache. We've had several cache bugs in the past, and caching is hard. The atstccfg app already has a --no-cache arg, this just adds it to ORT, which allows users to disable the cache if there's an issue, without having to modify ORT, just their cron. (cherry picked from commit 9c65e69) Co-authored-by: Robert Butts <rob05c@users.noreply.github.com>
1 parent 9d1261f commit 92a1428

File tree

2 files changed

+39
-32
lines changed

2 files changed

+39
-32
lines changed

traffic_ops/ort/atstccfg/toreq/toreq.go

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -242,45 +242,44 @@ func GetDeliveryServiceServers(cfg config.TCCfg, dsIDs []int, serverIDs []int) (
242242
if err != nil {
243243
return errors.New("getting delivery service servers from Traffic Ops '" + MaybeIPStr(reqInf) + "': " + err.Error())
244244
}
245+
dss := obj.(*[]tc.DeliveryServiceServer)
246+
*dss = toDSS.Response
247+
return nil
248+
})
249+
if err != nil {
250+
return nil, errors.New("getting delivery service servers: " + err.Error())
251+
}
245252

246-
serverIDsMap := map[int]struct{}{}
247-
for _, id := range serverIDs {
248-
serverIDsMap[id] = struct{}{}
249-
}
253+
serverIDsMap := map[int]struct{}{}
254+
for _, id := range serverIDs {
255+
serverIDsMap[id] = struct{}{}
256+
}
257+
dsIDsMap := map[int]struct{}{}
258+
for _, id := range dsIDs {
259+
dsIDsMap[id] = struct{}{}
260+
}
250261

251-
dsIDsMap := map[int]struct{}{}
252-
for _, id := range dsIDs {
253-
dsIDsMap[id] = struct{}{}
262+
// Older TO's may ignore the server ID list, so we need to filter them out manually to be sure.
263+
// Also, if DeliveryServiceServersAlwaysGetAll, we need to filter here anyway.
264+
filteredDSServers := []tc.DeliveryServiceServer{}
265+
for _, dsServer := range dsServers {
266+
if dsServer.Server == nil || dsServer.DeliveryService == nil {
267+
continue // TODO warn? error?
254268
}
255-
256-
// Older TO's may ignore the server ID list, so we need to filter them out manually to be sure.
257-
filteredDSServers := []tc.DeliveryServiceServer{}
258-
for _, dsServer := range toDSS.Response {
259-
if dsServer.Server == nil || dsServer.DeliveryService == nil {
260-
continue // TODO warn? error?
261-
}
262-
if len(serverIDsMap) > 0 {
263-
if _, ok := serverIDsMap[*dsServer.Server]; !ok {
264-
continue
265-
}
269+
if len(serverIDsMap) > 0 {
270+
if _, ok := serverIDsMap[*dsServer.Server]; !ok {
271+
continue
266272
}
267-
if len(dsIDsMap) > 0 {
268-
if _, ok := dsIDsMap[*dsServer.DeliveryService]; !ok {
269-
continue
270-
}
273+
}
274+
if len(dsIDsMap) > 0 {
275+
if _, ok := dsIDsMap[*dsServer.DeliveryService]; !ok {
276+
continue
271277
}
272-
filteredDSServers = append(filteredDSServers, dsServer)
273278
}
274-
275-
dss := obj.(*[]tc.DeliveryServiceServer)
276-
*dss = filteredDSServers
277-
return nil
278-
})
279-
if err != nil {
280-
return nil, errors.New("getting delivery service servers: " + err.Error())
279+
filteredDSServers = append(filteredDSServers, dsServer)
281280
}
282281

283-
return dsServers, nil
282+
return filteredDSServers, nil
284283
}
285284

286285
func GetServerProfileParameters(cfg config.TCCfg, profileName string) ([]tc.Parameter, error) {

traffic_ops/ort/traffic_ops_ort.pl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
my $override_hostname_short = '';
4646
my $override_hostname_full = '';
4747
my $override_domainname = '';
48+
my $use_cache = 1;
4849

4950
GetOptions( "dispersion=i" => \$dispersion, # dispersion (in seconds)
5051
"retries=i" => \$retries,
@@ -55,6 +56,7 @@
5556
"override_hostname_short=s" => \$override_hostname_short,
5657
"override_hostname_full=s" => \$override_hostname_full,
5758
"override_domainname=s" => \$override_domainname,
59+
"use_cache=i" => \$use_cache,
5860
);
5961

6062
if ( $#ARGV < 1 ) {
@@ -356,6 +358,7 @@ sub usage {
356358
print "\t override_hostname_short=<text> => override the short hostname of the OS for config generation. Default = ''.\n";
357359
print "\t override_hostname_full=<text> => override the full hostname of the OS for config generation. Default = ''.\n";
358360
print "\t override_domainname=<text> => override the domainname of the OS for config generation. Default = ''.\n";
361+
print "\t use_cache=<0|1> => whether to use cached Traffic Ops data for config generation. Default = 1, use cache.\n";
359362
print "====-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-====\n";
360363
exit 1;
361364
}
@@ -1505,7 +1508,12 @@ sub lwp_get {
15051508

15061509
my ( $TO_USER, $TO_PASS ) = split( /:/, $TM_LOGIN );
15071510

1508-
$response_content = `$atstccfg_cmd --traffic-ops-user='$TO_USER' --traffic-ops-password='$TO_PASS' --traffic-ops-url='$request' --log-location-error=stderr --log-location-warning=stderr --log-location-info=null 2>$atstccfg_log_path`;
1511+
my $no_cache_arg = '';
1512+
if ( $use_cache == 0 ) {
1513+
$no_cache_arg = '--no-cache';
1514+
}
1515+
1516+
$response_content = `$atstccfg_cmd $no_cache_arg --traffic-ops-user='$TO_USER' --traffic-ops-password='$TO_PASS' --traffic-ops-url='$request' --log-location-error=stderr --log-location-warning=stderr --log-location-info=null 2>$atstccfg_log_path`;
15091517

15101518
my $atstccfg_exit_code = $?;
15111519
$atstccfg_exit_code = atstccfg_code_to_http_code($atstccfg_exit_code);

0 commit comments

Comments
 (0)