-
Notifications
You must be signed in to change notification settings - Fork 98
Description
I've been wondering whether it's possible to run multiple instances of mirrorbits (meaning: for different projects, with a different set of mirrors) on the same host.
As you can use multiple config files and the config does allow you to set RedisDB which then seems to select a different DB, this should probably work?
However, the instances then still detect each other on startup: 2018/01/28 11:04:07.140 CET -> Node mirrorbits-21868 joined the cluster
As far as I understood the code, this is because it does some broadcast communication through the database, and that just uses the static string "HELLO" as a marker.
My attempt to fix this was to add the RedisDB-number to the string like that:
--- a/daemon/cluster.go
+++ b/daemon/cluster.go
@@ -11,6 +11,7 @@ import (
"sync"
"time"
+ . "github.com/etix/mirrorbits/config"
"github.com/etix/mirrorbits/database"
"github.com/etix/mirrorbits/mirrors"
"github.com/etix/mirrorbits/utils"
@@ -94,6 +95,7 @@ func (c *cluster) Stop() {
func (c *cluster) clusterLoop() {
clusterChan := make(chan string, 10)
announceTicker := time.NewTicker(1 * time.Second)
+ clusterAnnWithId := clusterAnnounce+fmt.Sprintf("%d", GetConfig().RedisDB)
c.refreshNodeList(c.nodeID, c.nodeID)
c.redis.Pubsub.SubscribeEvent(database.CLUSTER, clusterChan)
@@ -106,18 +108,18 @@ func (c *cluster) clusterLoop() {
case <-announceTicker.C:
c.announce()
case data := <-clusterChan:
- if !strings.HasPrefix(data, clusterAnnounce+" ") {
+ if !strings.HasPrefix(data, clusterAnnWithId+" ") {
// Garbage
continue
}
- c.refreshNodeList(data[len(clusterAnnounce)+1:], c.nodeID)
+ c.refreshNodeList(data[len(clusterAnnWithId)+1:], c.nodeID)
}
}
}
func (c *cluster) announce() {
r := c.redis.Get()
- database.Publish(r, database.CLUSTER, fmt.Sprintf("%s %s", clusterAnnounce, c.nodeID))
+ database.Publish(r, database.CLUSTER, fmt.Sprintf("%s%d %s", clusterAnnounce, GetConfig().RedisDB, c.nodeID))
r.Close()
}That seems to work, the instances no longer see each other. Is that really all that's needed, or am I overlooking something here that will cause problems down the road?