Skip to content

Replica Sets

Luke Lovett edited this page Sep 24, 2014 · 18 revisions

ReplicaSet collection

Methods:

  • POST - create and get up new ReplicaSet

    Example:

{
  "preset": "basic.json", // [optional] - configuration file on server, e.g., configurations/rs/basic.json
  "version": "26-release", // [optional] - release to use, as defined in configuration file
  "id": "default",  // [optional] replica set name
  "auth_key": "secret phrase",   // [optional]  - authentication key
  "login": "admin", // [optional] - username for the admin collection
  "password": "adminpass", // [optional] - password
  "timeout": 300,  // [optional] - (default: 300), specify how long, in seconds, a command can take before server times out.
  "sslParams": { "sslCAFile" : "~/ca.pem" }, // [optional] - SSL options http://docs.mongodb.org/manual/administration/ssl/
  "members": // list of member config
     [ {"rsParams": {"hidden":true, "priority":0}, "procParams": {"port":3333, "smallfiles": true}},
       {"rsParams":{"arbiterOnly":true}, "procParams": {"port": 3334}},
       {"sslParams": { "sslCAFile" : "~/ca.pem" }}, // use default parameters with SSL
       {}  // use default parameters
     ]
}

If preset is specified, parameters are first loaded from the server-side configuration file, e.g., configurations/rs/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/rs/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.

mongo-orchestration uses specific values for members parameters for best performance:

{"noprealloc": true, "nojournal": true, "smallfiles": true, "oplogSize": 10}

Each of members has two type of parameters:

{
 "auth_key": "secret phrase",
 "id": "default",
 "members": [{"_id": 0,
               "host": "localhost:3333",
               "server_id": "0438e87a-3487-47a1-96f7-b95f533b6387"},
              {"_id": 1,
               "host": "localhost:3334",
               "server_id": "aa1acb8c-bc8e-4490-acea-945be43cab04"},
              {"_id": 2,
               "host": "localhost:1025",
               "server_id": "bc0bd1fd-826e-401e-8033-f3203e922621"},
              {"_id": 3,
               "host": "localhost:1026",
               "server_id": "c933572d-4824-42a7-a0d9-3386335a945a"}
           ],
 "orchestration": "rs",
 "uri": "localhost:3333,localhost:3334,localhost:1025,localhost:1026/?replicaSet=default",
 "mongodb_uri": "mongodb://localhost:3333,localhost:3334,localhost:1025,localhost:1026/?replicaSet=default"}
 + 500 - Returned if create replica set was fail

Parameters:

  • repl id - string contains the replica set id

Methods:

  • POST - Issue a command to the ReplicaSet.

The request body is of the form {"action": "<COMMAND NAME>"}.

Currently available commands are as follows:

  • reset - Ensure all members of the ReplicaSet are available, starting any that are not.

  • PUT - Create a new Replica Set with the given repl-id.

This functions in much the same way as a POST request to /replica_sets, 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 /replica_sets.

  • GET - info about ReplicaSet object

    available response representations:

    • 200 - application/json

    Example:

{
 "auth_key": "secret phrase",
 "id": "default",
 "members": [{"_id": 0,
               "host": "localhost:3333",
               "server_id": "0438e87a-3487-47a1-96f7-b95f533b6387"},
              {"_id": 1,
               "host": "localhost:3334",
               "server_id": "aa1acb8c-bc8e-4490-acea-945be43cab04"},
              {"_id": 2,
               "host": "localhost:1025",
               "server_id": "bc0bd1fd-826e-401e-8033-f3203e922621"},
              {"_id": 3,
               "host": "localhost:1026",
               "server_id": "c933572d-4824-42a7-a0d9-3386335a945a"}
           ]
}
+ 404 - Returned if the ReplicaSet does not exist
  • DELETE - remove ReplicaSet

    available response representations:

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

Parameters:

  • repl-id - string contains the replica set id

Methods:

  • POST - add new node to replica set

    Example:

{ "rsParams": { "hidden": true, "priority":0 }, "procParams": {"port": 4444} }
*available response representations:*
+ 200 - Returned list of all members

   Example:
{"_id": 4,
 "server_id": "657b7fce-c8bf-4d61-96a3-0d4325e8ee5d",
 "procInfo": {"alive": True,
               "name": "/usr/bin/mongod",
               "optfile": "/tmp/mongo-GNl2Qp",
               "params": {"auth": True,
                           "dbpath": "/tmp/mongo-Doob71",
                           "keyFile": "/tmp/mongo-Doob71/key",
                           "nojournal": True,
                           "noprealloc": True,
                           "oplogSize": 10,
                           "port": 4444,
                           "replSet": "default",
                           "smallfiles": True},
               "pid": 935},
 "rsInfo": {"hidden": True, "primary": False, "secondary": True},
 "statuses": {"locked": False, "mongos": False, "primary": False},
 "uri": "localhost:4444",
 "mongodb_uri": "mongodb://localhost:4444"}
+ 500 - Returned if create replica set was fail
  • GET - return list of ReplicaSets members

    available response representations:

    + 200 - application/json
    
      Example:
    
[{"member_id": 0,
  "uri": "/servers/0438e87a-3487-47a1-96f7-b95f533b6387"},
 {"member_id": 1,
  "uri": "/servers/aa1acb8c-bc8e-4490-acea-945be43cab04"},
 {"member_id": 2,
  "uri": "/servers/bc0bd1fd-826e-401e-8033-f3203e922621"},
 {"member_id": 3,
  "uri": "/servers/c933572d-4824-42a7-a0d9-3386335a945a"},
 {"member_id": 4,
  "uri": "/servers/657b7fce-c8bf-4d61-96a3-0d4325e8ee5d"}]
  + 404 - Returned if the ReplicaSet not exist

Parameters:

  • repl-id - string contains the replica set id
  • member-id - string contains the member id

Methods:

  • GET - info about member available response representations:
    • 200 - application/json Example:
{"_id": 0,
 "server_id": "0438e87a-3487-47a1-96f7-b95f533b6387",
 "procInfo": {"alive": True,
               "name": "/usr/bin/mongod",
               "optfile": "/tmp/mongo-uG9WXg",
               "params": {"auth": True,
                           "dbpath": "/tmp/mongo-3OsuAx",
                           "keyFile": "/tmp/mongo-3OsuAx/key",
                           "nojournal": True,
                           "noprealloc": True,
                           "oplogSize": 10,
                           "port": 3333,
                           "replSet": "default",
                           "smallfiles": True},
               "pid": 32607},
 "rsInfo": {"hidden": True, "primary": False, "secondary": True},
 "statuses": {"locked": False, "mongos": False, "primary": False},
 "uri": "localhost:3333",
 "mongodb_uri": "mongodb://localhost:3333"}
+ 404 - Returned if the member not exist
  • PUT - change member params

    Example:

{"rsParams": {"hidden": false, "priority": 5}}
*available response representations:*
+ 200 - application/json
  Example
{"_id": 0,
 "server_id": "74c74524-b66b-4f04-bbbc-14d78f86961c",
 "procInfo": {"alive": True,
               "name": "/usr/bin/mongod",
               "optfile": "/tmp/mongo-JV_MLO",
               "params": {"auth": True,
                           "dbpath": "/tmp/mongo-Yn2i5o",
                           "keyFile": "/tmp/mongo-Yn2i5o/key",
                           "nojournal": True,
                           "noprealloc": True,
                           "oplogSize": 10,
                           "port": 3333,
                           "replSet": "default",
                           "smallfiles": True},
               "pid": 2521},
 "rsInfo": {"primary": True, "secondary": False},
 "statuses": {"locked": False, "mongos": False, "primary": True},
 "uri": "localhost:3333",
 "mongodb_uri": "mongodb://localhost:3333"}
+ 500 - Returned if fail
  • DELETE - remove member from replica set (stopped instances and erase all data)

    available response representations:

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

Parameters:

Methods:

  • GET - return information about each of this Replica Set's servers (does not include hidden nodes).

    Example: Suppose we create a replica set with the following configuration:

{
    "members": [
        {"name": "mongo_0"},
        {"name": "mongo_1"},
        {
            "name": "secret_mongo",
            "rsParams": {
                "hidden": true,
                "priority": 0
            }
        }
    ]
}

Then a GET to this URI would return the following:

[{"uri": "/servers/79ec2446-c856-4325-ac17-7f17edc54264", "member_id": 0},
 {"uri": "/servers/53e9e56d-1922-411e-9a8a-f3cc35308889", "member_id": 1}]

Parameters:

  • repl-id - string contains the replica set id

Methods:

  • GET - return info about primary member

    Example:

{"_id": 2,
 "server_id": "7be3c58c-823e-447d-b2f7-e197a96255b2",
 "procInfo": {"alive": True,
               "name": "/usr/bin/mongod",
               "optfile": "/tmp/mongo-4DfJHa",
               "params": {"auth": True,
                           "dbpath": "/tmp/mongo-Ysc3IY",
                           "keyFile": "/tmp/mongo-Ysc3IY/key",
                           "nojournal": True,
                           "noprealloc": True,
                           "oplogSize": 10,
                           "port": 1025,
                           "replSet": "default",
                           "smallfiles": True},
               "pid": 2613},
 "rsInfo": {"primary": True, "secondary": False},
 "statuses": {"locked": False, "mongos": False, "primary": True},
 "uri": "localhost:1025",
 "mongodb_uri": "mongodb://localhost:1025"}

Parameters:

  • repl-id - string contains the replica set id

Methods:

  • GET - return list of secondaries servers

    available response representations:

    • 200 - application/json Example:
[{"_id": 3,
  "host": "localhost:1026",
  "server_id": "0606d2e7-0a09-4841-a5a5-95dd44f067cb"},
 {"_id": 4,
  "host": "localhost:4444",
  "server_id": "c1466b1b-7b93-481d-8747-4cf5ea32d3c1"}]
*available response representations:*

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

Parameters:

  • repl-id - string contains the replica set id

Methods:

  • GET - return list of all arbiters for ReplicaSet

    available response representations:

    • 200 - application/json Example:
[{"_id": 1,
  "host": "localhost:3334",
  "server_id": "18792b23-269b-4508-a54f-dc47639e26ee"
}]
*available response representations:*

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

Parameters:

  • repl-id - string contains the replica set id

Methods:

  • GET - returl list of all hidden servers from ReplicaSet available response representations:
    • 200 - application/json Example:
[{"_id": 4,
  "host": "localhost:4444",
  "server_id": "dda3d844-3633-4279-bbf5-a79a58661b60"
}]
*available response representations:*

  + 200 - if the primary stepdown successfully
  + 500 - if an error occurred when stepdown primary server
Clone this wiki locally