rwynn / monstache

a go daemon that syncs MongoDB to Elasticsearch in realtime. you know, for search.
https://rwynn.github.io/monstache-site/
MIT License
1.28k stars 180 forks source link

Unable to enable cluster mode: (NotMaster) not master #327

Open gate3 opened 4 years ago

gate3 commented 4 years ago

I keep encountering this error when trying to start cluster mode. My config.toml has the cluster-name config

# enable clustering mode
cluster-name = 'HA'

I am using docker and starting two different containers

version: '3.4'
services:
    monstache1:
        image: rwynn/monstache:latest
        command:
            -worker worker1 -f /config.toml && -worker worker2 -f /config.toml && -worker worker3 -f /config.toml
        container_name: monstache1
        restart: on-failure
        volumes:
            - ./config.toml:/config.toml
        network_mode: "host"
monstache2:
        image: rwynn/monstache:latest
        command:
            -worker worker1 -f /config.toml && -worker worker2 -f /config.toml && -worker worker3 -f /config.toml
        container_name: monstache2
        restart: on-failure
        volumes:
            - ./config.toml:/config.toml
        network_mode: "host"

I am also getting an error for the http server: Unable to serve http at address :8081: listen tcp: address 8081: missing port in address

rwynn commented 4 years ago

I think you need to specify the http-server-addr like this...

# the default value for this is :8080
http-server-addr = ":8081"

where part before :, if supplied, is hostname, defaults to localhost.

Your command can be as simple as...

command:
           -f /config.toml

The pair of processes will join a cluster HA and only 1 will sync while the other will be a hot standby.

I don't think you need workers, but if you want to configure those you need to start a process for each worker.

monstache -workers a -workers b -workers c -worker a
monstache -workers a -workers b -workers c -worker b
monstache -workers a -workers b -workers c -worker c

Each process is told about all 3 worker names [a, b, c] and also is assigned one of the three (last arg).

With a config file config.toml above would be like

workers = ["a", "b", "c"]
monstache -f config.toml -worker a
monstache -f config.toml -worker b
monstache -f config.toml -worker c
gate3 commented 4 years ago

Thank you for getting back. I made the changes, I stopped using workers and simplified the command as suggested, however, the error persists

ERROR 2020/01/03 21:16:41 Unable to enable cluster mode: (NotMaster) not master

New look of my docker-compose file

monstache1:
        image: rwynn/monstache:latest
        command:
            -f /config.toml --enable-http-server --http-server-addr=:8081   
        container_name: monstache1
        restart: on-failure
        volumes:
            - ./config.toml:/config.toml
        network_mode: "host"
    monstache2:
        image: rwynn/monstache:latest
        command:
            -f /config.toml        
        container_name: monstache2
        restart: on-failure
        volumes:
            - ./config.toml:/config.toml
        network_mode: "host"

I still also have this in my config.toml

cluster-name = "HA"

rwynn commented 4 years ago

Is MongoDB started as a replica set according to...?

https://rwynn.github.io/monstache-site/start/#usage https://docs.mongodb.com/manual/tutorial/convert-standalone-to-replica-set/

This message is coming from the go driver. Check the hostname of your primary node in MongoDB and update the mongo-url connection string according to https://docs.mongodb.com/manual/reference/connection-string/.

rwynn commented 4 years ago

Here is a folder that sets up and runs monstache from scratch on docker...

https://github.com/rwynn/monstache/tree/rel6/docker/test

rwynn commented 4 years ago

The code that seems to be failing is https://github.com/rwynn/monstache/blob/rel6/monstache.go#L1300. When cluster mode is enabled monstache needs to create a TTL index. And that index creation is failing.

gmxu commented 4 years ago

Hi, I am getting the same error with cluster mode enabled when I am supplying a connection with with all the hosts in the replica set like this: mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myRepl

The master host changes between any of the 3 hosts and whenever the master host isn't the first one listed in the connection string I encounter the Unable to enable cluster mode: (NotMaster) not master error. Any ideas?

rwynn commented 4 years ago

This would be the code in monstache that is failing. It needs to create an index in cluster mode.

func (ic *indexClient) ensureClusterTTL() error {
    io := options.Index()
    io.SetName("expireAt")
    io.SetBackground(true)
    io.SetExpireAfterSeconds(30)
    im := mongo.IndexModel{
        Keys:    bson.M{"expireAt": 1},
        Options: io,
    }
    col := ic.mongo.Database(ic.config.ConfigDatabaseName).Collection("cluster")
    iv := col.Indexes()
    _, err := iv.CreateOne(context.Background(), im)
    return err
}

This should be enough to setup a simple example with the golang driver and replicate the issue against a cluster. Are you able to replicate it?

rwynn commented 4 years ago

What version of monstache are you using? Could the issue be this one in the driver? https://jira.mongodb.org/browse/GODRIVER-1428

Monstache 6.5.0+ should have this fix if that is the issue.