Skip to content
Snippets Groups Projects
Commit ea660b5b authored by Sergey Yakubov's avatar Sergey Yakubov
Browse files

sharded mongo

parent edaf10c1
No related branches found
No related tags found
No related merge requests found
......@@ -105,7 +105,8 @@ Error MongoDBClient::InsertBsonDocument(const bson_p& document, bool ignore_dupl
if (mongo_err.code == MONGOC_ERROR_DUPLICATE_KEY) {
return ignore_duplicates ? nullptr : TextError(DBError::kDuplicateID);
}
return TextError(DBError::kInsertError);
return TextError(std::string(DBError::kInsertError) + " - " + mongo_err.message);
}
return nullptr;
......
......@@ -31,6 +31,7 @@ job "asapo-brokers" {
type = "fluentd"
config {
fluentd-address = "localhost:9881"
fluentd-async-connect = true
tag = "asapo.docker"
}
}
......@@ -54,7 +55,7 @@ job "asapo-brokers" {
}
check_restart {
limit = 2
grace = "15s"
grace = "90s"
ignore_warnings = false
}
}
......@@ -70,6 +71,52 @@ job "asapo-brokers" {
destination = "secrets/secret.key"
change_mode = "restart"
}
}
} #task brokers
task "mongos-broker" {
driver = "docker"
config {
network_mode = "host"
image = "mongo:4.0.0"
dns_servers = ["127.0.0.1"]
command = "mongos"
args = ["--config","local/mongo-mongos.yaml"]
}
resources {
network {
port "mongos" {
static = 27016
}
}
}
service {
name = "mongos-broker"
check {
type = "script"
name = "mongos-broker-alive"
command = "mongo"
args = ["--host","${attr.unique.network.ip-address}","--port","27016","--eval","db.version()"]
interval = "10s"
timeout = "5s"
}
check_restart {
limit = 2
grace = "90s"
ignore_warnings = false
}
}
template {
source = "@NOMAD_INSTALL@/mongo-mongos.yaml.tpl"
destination = "local/mongo-mongos.yaml"
change_mode = "restart"
}
} # task mongos
}
}
......@@ -12,7 +12,7 @@ job "asapo-mongo-sharded" {
count = 1
restart {
attempts = 0
attempts = 2
interval = "3m"
delay = "15s"
mode = "fail"
......@@ -46,12 +46,12 @@ job "asapo-mongo-sharded" {
type = "script"
name = "alive"
command = "mongo"
args = ["--port","27010","--eval","db.version()"]
args = ["--host","${attr.unique.network.ip-address}","--port","27010","--eval","db.version()"]
interval = "10s"
timeout = "5s"
}
check_restart {
limit = 0
limit = 2
grace = "90s"
ignore_warnings = false
}
......@@ -70,7 +70,7 @@ job "asapo-mongo-sharded" {
count = 1
restart {
attempts = 0
attempts = 2
interval = "3m"
delay = "15s"
mode = "fail"
......@@ -104,12 +104,12 @@ job "asapo-mongo-sharded" {
type = "script"
name = "alive"
command = "mongo"
args = ["--port","27011","--eval","db.version()"]
args = ["--host","${attr.unique.network.ip-address}","--port","27011","--eval","db.version()"]
interval = "10s"
timeout = "5s"
}
check_restart {
limit = 0
limit = 2
grace = "90s"
ignore_warnings = false
}
......@@ -121,59 +121,117 @@ job "asapo-mongo-sharded" {
}
}
} # shard1 group
group "mongos" {
count = 1
restart {
attempts = 0
interval = "3m"
delay = "15s"
mode = "fail"
}
group "mongo-shard2" {
count = 1
task "mongos" {
driver = "docker"
restart {
attempts = 2
interval = "3m"
delay = "15s"
mode = "fail"
}
config {
network_mode = "host"
image = "mongo:4.0.0"
dns_servers = ["127.0.0.1"]
command = "mongos"
args = ["--config","local/mongo-mongos.yaml"]
task "mongo-shard2" {
driver = "docker"
}
config {
network_mode = "host"
image = "mongo:4.0.0"
dns_servers = ["127.0.0.1"]
volumes = ["/${meta.shared_storage}/mongodb_shard2:/data/db"]
command = "mongod"
args = ["--config","local/mongo-shardsrv.yaml"]
resources {
network {
port "mongos" {
static = 27017
}
resources {
network {
port "shard" {
static = 27012
}
}
}
}
service {
port = "mongos"
name = "mongos"
check {
type = "script"
name = "alive"
command = "mongo"
args = ["--eval","db.version()"]
interval = "10s"
timeout = "5s"
service {
port = "shard"
name = "mongo-shard2"
check {
type = "script"
name = "alive"
command = "mongo"
args = ["--host","${attr.unique.network.ip-address}","--port","27012","--eval","db.version()"]
interval = "10s"
timeout = "5s"
}
check_restart {
limit = 2
grace = "90s"
ignore_warnings = false
}
}
check_restart {
limit = 0
grace = "90s"
ignore_warnings = false
template {
source = "@NOMAD_INSTALL@/mongo-shardsrv.yaml.tpl"
destination = "local/mongo-shardsrv.yaml"
change_mode = "restart"
}
}
template {
source = "@NOMAD_INSTALL@/mongo-mongos.yaml.tpl"
destination = "local/mongo-mongos.yaml"
change_mode = "restart"
} # shard2 group
group "mongo-shard3" {
count = 1
restart {
attempts = 2
interval = "3m"
delay = "15s"
mode = "fail"
}
}
} # mongos group
task "mongo-shard3" {
driver = "docker"
config {
network_mode = "host"
image = "mongo:4.0.0"
dns_servers = ["127.0.0.1"]
volumes = ["/${meta.shared_storage}/mongodb_shard3:/data/db"]
command = "mongod"
args = ["--config","local/mongo-shardsrv.yaml"]
}
resources {
network {
port "shard" {
static = 27013
}
}
}
service {
port = "shard"
name = "mongo-shard3"
check {
type = "script"
name = "alive"
command = "mongo"
args = ["--host","${attr.unique.network.ip-address}","--port","27013","--eval","db.version()"]
interval = "10s"
timeout = "5s"
}
check_restart {
limit = 2
grace = "90s"
ignore_warnings = false
}
}
template {
source = "@NOMAD_INSTALL@/mongo-shardsrv.yaml.tpl"
destination = "local/mongo-shardsrv.yaml"
change_mode = "restart"
}
}
} # shard3 group
}
......@@ -64,7 +64,53 @@ job "asapo-receivers" {
destination = "local/config.json"
change_mode = "restart"
}
}
} #task receivers
task "mongos-receiver" {
driver = "docker"
config {
network_mode = "host"
image = "mongo:4.0.0"
dns_servers = ["127.0.0.1"]
command = "mongos"
args = ["--config","local/mongo-mongos.yaml"]
}
resources {
network {
port "mongos" {
static = 27015
}
}
}
service {
name = "mongos-receiver"
check {
type = "script"
name = "mongos-receiver-alive"
command = "mongo"
args = ["--host","${attr.unique.network.ip-address}","--port","27015","--eval","db.version()"]
interval = "10s"
timeout = "5s"
}
check_restart {
limit = 2
grace = "90s"
ignore_warnings = false
}
}
template {
source = "@NOMAD_INSTALL@/mongo-mongos.yaml.tpl"
destination = "local/mongo-mongos.yaml"
change_mode = "restart"
}
} # task mongos
}
}
......@@ -21,6 +21,7 @@ job "asapo-services" {
type = "fluentd"
config {
fluentd-address = "localhost:9881"
fluentd-async-connect = true
tag = "asapo.docker"
}
}
......@@ -77,6 +78,7 @@ job "asapo-services" {
type = "fluentd"
config {
fluentd-address = "localhost:9881"
fluentd-async-connect = true
tag = "asapo.docker"
}
}
......
{
"BrokerDbAddress":"mongo.service.asapo:27017",
"BrokerDbAddress":"{{ env "attr.unique.network.ip-address" }}:27016",
"MonitorDbAddress":"influxdb.service.asapo:8086",
"MonitorDbName": "asapo_brokers",
"port":{{ env "NOMAD_PORT_broker" }},
......
......@@ -3,15 +3,18 @@
mongoaddr=`dig +short @127.0.0.1 mongo-config-srv.service.asapo | head -1`
cont=$(ssh $mongoaddr bash -c "'docker ps | grep mongo-config-srv'")
image=`echo "${cont##* }"`
ssh $mongoaddr docker exec $image bash -c "'echo \"rs.initiate()\" | mongo --port 27010'"
ssh $mongoaddr docker exec $image bash -c "'echo \"rs.initiate()\" | mongo --host $mongoaddr --port 27010'"
mongoaddr=`dig +short @127.0.0.1 mongos.service.asapo | head -1`
mongoaddr=`dig +short @127.0.0.1 mongos-broker.service.asapo | head -1`
cont=$(ssh $mongoaddr bash -c "'docker ps | grep mongos'")
image=`echo "${cont##* }"`
shardaddr=`dig +short @127.0.0.1 mongo-shard1.service.asapo | head -1`
shardaddr1=`dig +short @127.0.0.1 mongo-shard1.service.asapo | head -1`
shardaddr2=`dig +short @127.0.0.1 mongo-shard2.service.asapo | head -1`
shardaddr3=`dig +short @127.0.0.1 mongo-shard3.service.asapo | head -1`
ssh $mongoaddr docker exec $image bash -c "'echo \"sh.addShard('\"'$shardaddr:27011'\"')\" | mongo'"
ssh $mongoaddr docker exec $image bash -c "'echo \"sh.addShard('\"'$shardaddr1:27011'\"')\" | mongo --host $mongoaddr --port 27016'"
ssh $mongoaddr docker exec $image bash -c "'echo \"sh.addShard('\"'$shardaddr2:27012'\"')\" | mongo --host $mongoaddr --port 27016 '"
ssh $mongoaddr docker exec $image bash -c "'echo \"sh.addShard('\"'$shardaddr3:27013'\"')\" | mongo --host $mongoaddr --port 27016 '"
{
"MonitorDbAddress":"influxdb.service.asapo:8086",
"MonitorDbName": "asapo_receivers",
"BrokerDbAddress":"mongo.service.asapo:27017",
"BrokerDbAddress":"{{ env "attr.unique.network.ip-address" }}:27015",
"AuthorizationServer": "asapo-authorizer.service.asapo:5007",
"AuthorizationInterval": 10000,
"ListenPort": {{ env "NOMAD_PORT_recv" }},
......
......@@ -2,8 +2,13 @@
nomad run asapo-nginx.nmd
nomad run asapo-logging.nmd
nomad run asapo-mongo.nmd
nomad run asapo-mongo-sharded.nmd
#if mongo replica sets and shards not created yet might be necessary to wait here, than start mongos (run init_mongo.sh first time to create replicas,
#then start mongos (e.g. in asapo-brokers job), then run init_mongo.sh once more
nomad run asapo-brokers.nmd
nomad run asapo-services.nmd
nomad run asapo-perfmetrics.nmd
nomad run asapo-receivers.nmd
nomad run asapo-brokers.nmd
......@@ -2,7 +2,7 @@
nomad stop asapo-nginx
nomad stop asapo-logging
nomad stop asapo-mongo
nomad stop asapo-mongo-sharded
nomad stop asapo-services
nomad stop asapo-perfmetrics
nomad stop asapo-receivers
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment