Skip to content

Commit

Permalink
Add "fallback read" mode.
Browse files Browse the repository at this point in the history
If `Origin.EnableFallbackRead` is set, then the origin will be selected by the director
to serve clients if there are no available caches.

Fixes #608
  • Loading branch information
bbockelm committed Jan 10, 2024
1 parent 1fa0e9f commit 2e63437
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 33 deletions.
17 changes: 9 additions & 8 deletions director/cache_ads.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ type (
}

ServerAd struct {
Name string
AuthURL url.URL
URL url.URL // This is server's XRootD URL for file transfer
WebURL url.URL // This is server's Web interface and API
Type ServerType
Latitude float64
Longitude float64
EnableWrite bool
Name string
AuthURL url.URL
URL url.URL // This is server's XRootD URL for file transfer
WebURL url.URL // This is server's Web interface and API
Type ServerType
Latitude float64
Longitude float64
EnableWrite bool
EnableFallbackRead bool // True if reads from the origin are permitted when no cache is available
}

ServerType string
Expand Down
11 changes: 6 additions & 5 deletions director/origin_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ import (

type (
OriginAdvertise struct {
Name string `json:"name"`
URL string `json:"url"` // This is the url for origin's XRootD service and file transfer
WebURL string `json:"web_url,omitempty"` // This is the url for origin's web engine and APIs
Namespaces []NamespaceAd `json:"namespaces"`
EnableWrite bool `json:"enablewrite"`
Name string `json:"name"`
URL string `json:"url"` // This is the url for origin's XRootD service and file transfer
WebURL string `json:"web_url,omitempty"` // This is the url for origin's web engine and APIs
Namespaces []NamespaceAd `json:"namespaces"`
EnableWrite bool `json:"enablewrite"`
EnableFallbackRead bool `json:"enable-fallback-read"` // True if the origin will allow direct client reads when no caches are available
}
)

Expand Down
38 changes: 24 additions & 14 deletions director/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func RedirectToCache(ginCtx *gin.Context) {

authzBearerEscaped := getAuthzEscaped(ginCtx.Request)

namespaceAd, _, cacheAds := GetAdsForPath(reqPath)
namespaceAd, originAds, cacheAds := GetAdsForPath(reqPath)
// if GetAdsForPath doesn't find any ads because the prefix doesn't exist, we should
// report the lack of path first -- this is most important for the user because it tells them
// they're trying to get an object that simply doesn't exist
Expand All @@ -189,13 +189,22 @@ func RedirectToCache(ginCtx *gin.Context) {
}
// If the namespace prefix DOES exist, then it makes sense to say we couldn't find a valid cache.
if len(cacheAds) == 0 {
ginCtx.String(404, "No cache found for path\n")
return
}
cacheAds, err = SortServers(ipAddr, cacheAds)
if err != nil {
ginCtx.String(500, "Failed to determine server ordering")
return
for _, originAd := range originAds {
if originAd.EnableFallbackRead {
cacheAds = append(cacheAds, originAd)
break
}
}
if len(cacheAds) == 0 {
ginCtx.String(http.StatusNotFound, "No cache found for path")
return
}
} else {
cacheAds, err = SortServers(ipAddr, cacheAds)
if err != nil {
ginCtx.String(http.StatusInternalServerError, "Failed to determine server ordering")
return
}
}
redirectURL := getRedirectURL(reqPath, cacheAds[0], namespaceAd.RequireToken)

Expand Down Expand Up @@ -462,12 +471,13 @@ func registerServeAd(engineCtx context.Context, ctx *gin.Context, sType ServerTy
}

sAd := ServerAd{
Name: ad.Name,
AuthURL: *ad_url,
URL: *ad_url,
WebURL: *adWebUrl,
Type: sType,
EnableWrite: ad.EnableWrite,
Name: ad.Name,
AuthURL: *ad_url,
URL: *ad_url,
WebURL: *adWebUrl,
Type: sType,
EnableWrite: ad.EnableWrite,
EnableFallbackRead: ad.EnableFallbackRead,
}

hasOriginAdInCache := serverAds.Has(sAd)
Expand Down
8 changes: 8 additions & 0 deletions docs/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ type: bool
default: true
components: ["origin"]
---
name: Origin.EnableFallbackRead
description: >-
Set to `true` if the origin permits clients to directly read from it
when no cache service is available
type: bool
default: false
components: ["origin"]
---
name: Origin.Multiuser
description: >-
A bool indicating whether an origin is "multiuser", ie whether the underlying XRootD instance must be configured in multi user mode.
Expand Down
12 changes: 6 additions & 6 deletions origin_ui/advertise.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (server *OriginServer) CreateAdvertisement(name string, originUrl string, o

prefix := param.Origin_NamespacePrefix.GetString()

enableWrite := param.Origin_EnableWrite.GetBool()
// TODO: Need to figure out where to get some of these values
// so that they aren't hardcoded...
nsAd := director.NamespaceAd{
Expand All @@ -65,11 +64,12 @@ func (server *OriginServer) CreateAdvertisement(name string, originUrl string, o
BasePath: prefix,
}
ad = director.OriginAdvertise{
Name: name,
URL: originUrl,
WebURL: originWebUrl,
Namespaces: []director.NamespaceAd{nsAd},
EnableWrite: enableWrite,
Name: name,
URL: originUrl,
WebURL: originWebUrl,
Namespaces: []director.NamespaceAd{nsAd},
EnableWrite: param.Origin_EnableWrite.GetBool(),
EnableFallbackRead: param.Origin_EnableFallbackRead.GetBool(),
}

return ad, nil
Expand Down
1 change: 1 addition & 0 deletions param/parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions param/parameters_struct.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2e63437

Please sign in to comment.