Skip to content

Commit

Permalink
fix: FilePeers implies no Redis (#1251)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?

- If someone specified FilePeers, then we are assuming they don't want
to run Redis.

## Short description of the changes

- Simplify logic; if FilePeers, no redis and only local pubsub.
- Update some of the documentation.
  • Loading branch information
kentquirk authored Jul 26, 2024
1 parent 3ea3107 commit 31d2ce2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
24 changes: 8 additions & 16 deletions cmd/refinery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func main() {
os.Exit(1)
}

// set up the peer management and pubsub implementations
var peers peer.Peers
var pubsubber pubsub.PubSub
ptype, err := c.GetPeerManagementType()
Expand All @@ -124,24 +125,15 @@ func main() {
}
switch ptype {
case "file":
// we want to use the file peers object to ask if we have only one peer, so we need to instantiate it
// with a dummy metrics object. we'll replace it with the real one later.
peers = &peer.FilePeers{Cfg: c, Metrics: &metrics.NullMetrics{}}
// if we only have one, we can use the local pubsub implementation.
peerList, err := peers.GetPeers()
if err != nil {
panic(err)
}
if len(peerList) == 1 {
pubsubber = &pubsub.LocalPubSub{}
} else {
pubsubber = &pubsub.GoRedisPubSub{}
}
// now erase the peers Metrics object so that it will get injected with the right one later
peers.(*peer.FilePeers).Metrics = nil
// In the case of file peers, we do not use Redis for anything, including pubsub, so
// we use the local pubsub implementation. Even if we have multiple peers, these
// peers cannot communicate using pubsub.
peers = &peer.FilePeers{}
pubsubber = &pubsub.LocalPubSub{}
case "redis":
pubsubber = &pubsub.GoRedisPubSub{}
// if we're using redis, we need to set it up for both peers and pubsub
peers = &peer.RedisPubsubPeers{}
pubsubber = &pubsub.GoRedisPubSub{}
default:
// this should have been caught by validation
panic("invalid config option 'PeerManagement.Type'")
Expand Down
11 changes: 7 additions & 4 deletions config/metadata/configMeta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -835,12 +835,15 @@ groups:
Peer management is the mechanism by which Refinery locates its peers.
`file` means that Refinery gets its peer list from the Peers list in
this config file.
this config file. It also prevents Refinery from using a publish/subscribe
mechanism to propagate peer lists, stress levels, and configuration changes.
`redis` means that Refinery uses a Publish/Subscribe mechanism,
implemented on Redis, to propagate peer lists much more quickly than
the legacy mechanism. This is the recommended setting, especially for
new installations.
implemented on Redis, to propagate peer lists, stress levels, and
notification of configuration changes much more quickly than the
legacy mechanism. This is the recommended setting, especially for new
installations. If this is specified, fields in `RedisPeerManagement`
must also be set.
- name: Identifier
v1group: PeerManagement
Expand Down

0 comments on commit 31d2ce2

Please sign in to comment.