Skip to content

Sharded Clusters

Luke Lovett edited this page Sep 4, 2014 · 14 revisions

MongoDB Sharding Manual

Methods:

  • POST - create and get up new Shard Cluster

Shard Cluster Configuration contains:

  • id - cluster name (optional)
  • auth_key - authentication key (optional)
  • login - username for the admin collection (optional)
  • password - password (optional)
  • routers - list of routers configurations (required, default: [{}])
  • configsvrs - list of config servers configurations (required, default: [{}])
  • members - cluster's shards (required)
  • preset - configuration file on server with which to merge (optional)
  • version - release to use, as defined in configuration file (optional)

routers configuration is a server config with name=mongos configsvrs configuration is a server config with name=mongod and configsvr=true members configuration contains:

  • id - shard name
  • shardParams - server config if shard is a server , otherwise replicaset config. shardParams can contains option 'tags' as a list of shard tags.

Example:

{
  "preset": "basic.json", // [optional] - configuration file on server, e.g., configurations/sh/basic.json
  "version": "26-release", // [optional] - release to use, as defined in configuration file
  "id":"shard_cluster_1", // [optional]
  "auth_key": "secret", // [optional]  - authentication key
  "login": "admin", // [optional] - username for the admin collection
  "password":"adminpass",  // [optional] - password
  "sslParams": { "sslCAFile" : "~/ca.pem" }, // [optional] - SSL options http://docs.mongodb.org/manual/administration/ssl/
  "routers": [{"port":2323}, {}], // list of routers
  "configsvrs": [{"port": 2315}, {}, {}], // list of config servers
  "members": [  // list of members
      {"id": "sh01", "shardParams":{"tags": ["tag1", "tag2"]}}, // server
      {"id": "sh02", "shardParams": {"procParams": {"port":2320}, "tags": ["otherTag"]}}, // server
      {"id": "sh-rs-01", "shardParams": {"id": "rs1", "tags": ["replTag"], "members": [{}, {}]}},  // replicaset
   {} // server with default options
]}

If preset is specified, parameters are first loaded from the server-side configuration file, e.g., configurations/sh/basic.json, and then updated with any other supplied parameters. The update is a deep merge so that individual leaf values can be overridden by supplied parameters.

Minimal example:

{
  "preset": "basic.json", // [optional] - configuration file on server, e.g., configurations/sh/basic.json
}

In this minimal example, all parameters are supplied from the server-side configuration file. If id is not specified in the configuration file, a uuid is generated for the id.

The version field allows you to specify what release defined in the --config file to use when starting the Server. The config file must be provided to server.py on startup, and only releases defined within the file are valid to use. If this field is omitted, then Mongo Orchestration will choose the first release in the config file. If no config file was given, then Mongo Orchestration will start whatever binary is on the user's PATH. See also: /releases.

available response representations:

  • 200 - Returned if create shard cluster was successful

Example:

{"configsvrs": [{"hostname": "localhost:2315",
                  "id": "1429155e-0105-4726-8090-aa742a83a01f"},
                 {"hostname": "localhost:1025",
                  "id": "f0e9afa8-01c3-48b0-bb8c-27d5f8c31b58"},
                 {"hostname": "localhost:1026",
                  "id": "eee965a4-574e-4fe5-852a-7ed53e6e047c"}],
 "id": "shard_cluster_1",
 "members": [{"_id": "90cefef6-c091-4ae1-90f7-e03bb51a135a",
               "id": "dd2ed2bc-1a8d-49b6-a7cd-414c919a3586",
               "isServer": true,
               "tags": []},
              {"_id": "0d6901ea-1064-42ac-9311-0876d070bb9c",
               "id": "sh01",
               "isServer": true,
               "tags": ["tag1", "tag2"]},
              {"_id": "rs1",
               "id": "sh-rs-01",
               "isReplicaSet": true,
               "tags": ["replTag"]},
              {"_id": "34afd26e-3eef-4c55-ba63-7573cc7f3929",
               "id": "sh02",
               "isServer": true,
               "tags": ["otherTag"]}],
 "orchestration" : "sh",
 "routers": [{"hostname": "localhost:2323",
               "id": "e36d9885-d71b-4c16-ac58-f3b1d82a3c19"},
              {"hostname": "localhost:1027",
               "id": "7ed0eee0-ce7f-4ea7-ad1f-224ecbf0f082"}],
 "uri": "localhost:2323,localhost:1027",
 "mongodb_uri": "mongodb://localhost:2323,localhost:1027"}
  • 500 - Returned if create shard cluster was fail

Parameters:

  • sh id - string contains the shard cluster id

Methods:

  • PUT - Create a new Sharded Cluster with the given cluster-id.

This functions in much the same way as a POST request to /sharded_clusters except that the id is given as part of the URI rather than the request body. The response from the server is identical to that of a POST to /sharded_clusters.

  • GET - info about configuration

available response representations:

  • 200 - application/json

Example:

{"configsvrs": [{"hostname": "localhost:2315",
                  "id": "1429155e-0105-4726-8090-aa742a83a01f"},
                 {"hostname": "localhost:1025",
                  "id": "f0e9afa8-01c3-48b0-bb8c-27d5f8c31b58"},
                 {"hostname": "localhost:1026",
                  "id": "eee965a4-574e-4fe5-852a-7ed53e6e047c"}],
 "id": "shard_cluster_1",
 "members": [{"_id": "90cefef6-c091-4ae1-90f7-e03bb51a135a",
               "id": "dd2ed2bc-1a8d-49b6-a7cd-414c919a3586",
               "isServer": true,
               "tags": []},
              {"_id": "0d6901ea-1064-42ac-9311-0876d070bb9c",
               "id": "sh01",
               "isServer": true,
               "tags": ["tag1", "tag2"]},
              {"_id": "rs1",
               "id": "sh-rs-01",
               "isReplicaSet": true,
               "tags": ["replTag"]},
              {"_id": "34afd26e-3eef-4c55-ba63-7573cc7f3929",
               "id": "sh02",
               "isServer": true,
               "tags": ["otherTag"]}],
 "routers": [{"hostname": "localhost:2323",
               "id": "e36d9885-d71b-4c16-ac58-f3b1d82a3c19"},
              {"hostname": "localhost:1027",
               "id": "7ed0eee0-ce7f-4ea7-ad1f-224ecbf0f082"}]}
  • 404 - Returned if the Shard Cluster doesn't exist

  • DELETE - remove Shard Cluster

available response representations:

  • 204 - Returned if delete was successful
  • 400 - Returned if delete was fail

Parameters:

  • cluster-id - string contains the shard cluster id

Methods:

  • POST - add member to shard cluster

Example:

{ "id": "sh03" }  // is server

or

{ "id": "sh-rs", "shardParams": {"id": "rs7", "members": [{}, {}]}}  // is replica set

available response representations:

  • 200 - Returned info about new member

Example:

{"_id": "5bd0292c-485b-48c7-b67b-2b61f9137656",
 "id": "sh03",
 "isServer": true,
 "tags": []}

or

{
  "_id": "rs7",
  "id": "sh-rs",
  "isReplicaSet": true,
  "tags": []
}
  • 500 - Returned if create shard cluster was fail

  • GET - return list of Sharded Cluster's members

available response representations:

  • 200 - application/json

Example:

[{"uri": "/servers/d9025f00-f3d1-4924-bb63-2d08c0a56b0f",
  "shard_id": "b5de7c5d-a853-4328-b18f-25ad3233c38c",
  "isServer": true,
  "tags": []},
 {"uri": "/replica_sets/rs1",
  "shard_id": "sh-rs-01",
  "isReplicaSet": true,
  "tags": []},
 {"uri": "/replica_sets/rs7", "shard_id": "sh-rs", "isReplicaSet": true, "tags": []},
 {"uri": "/servers/0f5a8d24-5233-4652-8bf5-a0799ed3ba0c",
  "shard_id": "sh01",
  "isServer": true,
  "tags": ["tag1", "tag2"]},
 {"uri": "/servers/5bd0292c-485b-48c7-b67b-2b61f9137656",
  "shard_id": "sh03",
  "isServer": true,
  "tags": []},
 {"uri": "/servers/ed349746-3eb6-483c-821e-5a1dc0acbfd4",
  "shard_id": "sh02",
  "isServer": true,
  "tags": ["otherTag"]}
]
  • 404 - Returned if the Shard Cluster doesn't exist

Parameters:

  • cluster-id - string contains the shard cluster id
  • shard-id - string contains the shard id

Methods:

  • GET - info about member available response representations:

  • 200 - application/json

Example:

{ "_id": "0f5a8d24-5233-4652-8bf5-a0799ed3ba0c",
  "id": "sh01",
  "isServer": true,
  "tags": ["tag1", "tag2"]
}
  • 404 - Returned if the member doesn't exist

  • DELETE - remove member from shard cluster

available response representations:

  • 204 - application/json

Example:

{ "msg": "draining started successfully",  // shard still exists
  "ok": 1.0,
  "shard": "sh01",
  "state": "started"
}

or

{ "msg": "removeshard completed successfully",  // shard has removed
  "ok": 1.0,
  "shard": "sh01",
  "state": "completed"
}
  • 400 - Returned if delete was fail

Parameters:

  • cluster-id - string contains the shard cluster id

Methods:

  • GET - return list of config servers

available response representations:

  • 200 - application/json

Example:

[
 {"hostname": "localhost:2315",
  "id": "e5b737c3-ba74-455d-8d3f-968e31f66618"},
 {"hostname": "localhost:1025",
  "id": "9f1ff976-3693-4fac-ab27-d10e71c92422"},
 {"hostname": "localhost:1026",
  "id": "725dc748-a4df-4519-a9d4-05f0346da329"}
]

available response representations:

  • 200 - if the primary stepdown successfully
  • 500 - if an error occurred when stepdown primary server

Parameters:

  • cluster-id - string contains the replica set id

Methods:

  • GET - return list of all routers for a sharded cluster

available response representations:

  • 200 - application/json

Example:

[
 {"hostname": "localhost:2323",
  "id": "c37d5b66-fa36-4fc4-9508-2f17df9497b2"},
 {"hostname": "localhost:1027",
  "id": "a5d69ccc-75ff-4200-9add-d1212c4e9a50"}
]
  • POST - add new router to shard cluster

Example:

{"port": 2121}

available response representations:

  • 200 - Returned info about new router

Example:

{ "hostname": "localhost:2121",
   "id": "89b5c675-9cea-402b-a393-52dcd1353c75"
}
  • 500 - Returned if create shard cluster was fail

Parameters:

  • router-id - string contains the router id

Methods:

  • DELETE - delete router from shard cluster

available response representations:

  • 200 - Returned info about routers

Example:

{'ok': 1,
 'routers': [u'e5858165-929b-48bc-ac0d-87cf31655ea8', u'302ed013-5ce7-45e0-b5ba-132e6d52caec']}
  • 500 - Returned if delete router of shard cluster was fail
Clone this wiki locally