Back to Couchdb

``/{db}/_shards``

src/docs/src/api/database/shard.rst

3.5.17.0 KB
Original Source

.. Licensed under the Apache License, Version 2.0 (the "License"); you may not .. use this file except in compliance with the License. You may obtain a copy of .. the License at .. .. http://www.apache.org/licenses/LICENSE-2.0 .. .. Unless required by applicable law or agreed to in writing, software .. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT .. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the .. License for the specific language governing permissions and limitations under .. the License.

.. _api/db/shards:

================= /{db}/_shards

.. versionadded:: 2.0

.. http:get:: /{db}/_shards :synopsis: Displays the shard map layout of a database

The response will contain a list of database shards. Each shard will
have its internal database range, and the nodes on which replicas of
those shards are stored.

:param db: Database name
:<header Accept: - :mimetype:`application/json`
                 - :mimetype:`text/plain`
:>header Content-Type: - :mimetype:`application/json`
                       - :mimetype:`text/plain; charset=utf-8`
:>json object shards: Mapping of shard ranges to individual shard replicas
                      on each node in the cluster
:code 200: Request completed successfully
:code 400: Invalid database name
:code 401: Read privilege required
:code 403: Insufficient permissions / :ref:`Too many requests with invalid credentials<error/403>`
:code 415: Bad :header:`Content-Type` value
:code 500: Internal server error or timeout

**Request**:

.. code-block:: http

    GET /db/_shards HTTP/1.1
    Accept: */*
    Host: localhost:5984

**Response**:

.. code-block:: http

    HTTP/1.1 200 OK
    Cache-Control: must-revalidate
    Content-Length: 621
    Content-Type: application/json
    Date: Fri, 18 Jan 2019 19:55:14 GMT
    Server: CouchDB/2.4.0 (Erlang OTP/19)

    {
      "shards": {
        "00000000-1fffffff": [
          "[email protected]",
          "[email protected]",
          "[email protected]"
        ],
        "20000000-3fffffff": [
          "[email protected]",
          "[email protected]",
          "[email protected]"
        ],
        "40000000-5fffffff": [
          "[email protected]",
          "[email protected]",
          "[email protected]"
        ],
        "60000000-7fffffff": [
          "[email protected]",
          "[email protected]",
          "[email protected]"
        ],
        "80000000-9fffffff": [
          "[email protected]",
          "[email protected]",
          "[email protected]"
        ],
        "a0000000-bfffffff": [
          "[email protected]",
          "[email protected]",
          "[email protected]"
        ],
        "c0000000-dfffffff": [
          "[email protected]",
          "[email protected]",
          "[email protected]"
        ],
        "e0000000-ffffffff": [
          "[email protected]",
          "[email protected]",
          "[email protected]"
        ]
      }
    }

.. _api/db/shards/doc:

============================== /{db}/_shards/{docid}

.. http:get:: /{db}/_shards/{docid} :synopsis: Returns the specific shard in which a document is stored

Returns information about the specific shard into which a given document
has been stored, along with information about the nodes on which that
shard has a replica.

:param db: Database name
:param docid: Document ID
:<header Accept: - :mimetype:`application/json`
                 - :mimetype:`text/plain`
:>header Content-Type: - :mimetype:`application/json`
                       - :mimetype:`text/plain; charset=utf-8`
:>json string range: The shard range in which the document is stored
:>json array nodes: List of nodes serving a replica of the shard
:code 200: Request completed successfully
:code 401: Read privilege required
:code 403: Insufficient permissions / :ref:`Too many requests with invalid credentials<error/403>`
:code 404: Database or document not found
:code 500: Internal server error or timeout

**Request**:

.. code-block:: http

    GET /db/_shards/docid HTTP/1.1
    Accept: */*
    Host: localhost:5984

**Response**:

.. code-block:: http

    HTTP/1.1 200 OK
    Cache-Control: must-revalidate
    Content-Length: 94
    Content-Type: application/json
    Date: Fri, 18 Jan 2019 20:26:33 GMT
    Server: CouchDB/2.3.0-9d4cb03c2 (Erlang OTP/19)

    {
      "range": "e0000000-ffffffff",
      "nodes": [
        "[email protected]",
        "[email protected]",
        "[email protected]"
      ]
    }

.. _api/db/sync_shards:

====================== /{db}/_sync_shards

.. versionadded:: 2.3.1

.. http:post:: /{db}/_sync_shards :synopsis: Trigger a synchronization of all shard replicas in the database

For the given database, force-starts internal shard synchronization
for all replicas of all database shards.

This is typically only used when performing cluster maintenance,
such as :ref:`moving a shard <cluster/sharding/move>`.

:param db: Database name
:<header Accept: - :mimetype:`application/json`
                 - :mimetype:`text/plain`
:>header Content-Type: - :mimetype:`application/json`
                       - :mimetype:`text/plain; charset=utf-8`
:>json boolean ok: Operation status. Available in case of success
:>json string error: Error type. Available if response code is ``4xx``
:>json string reason: Error description. Available if response code is
  ``4xx``
:code 202: Request accepted
:code 400: Invalid database name
:code 401: CouchDB Server Administrator privileges required
:code 403: Insufficient permissions / :ref:`Too many requests with invalid credentials<error/403>`
:code 404: Database not found
:code 500: Internal server error or timeout

**Request**:

.. code-block:: http

    POST /db/_sync_shards HTTP/1.1
    Host: localhost:5984
    Accept: */*

**Response**:

.. code-block:: http

    HTTP/1.1 202 Accepted
    Cache-Control: must-revalidate
    Content-Length: 12
    Content-Type: application/json
    Date: Fri, 18 Jan 2019 20:19:23 GMT
    Server: CouchDB/2.3.0-9d4cb03c2 (Erlang OTP/19)
    X-Couch-Request-ID: 14f0b8d252
    X-CouchDB-Body-Time: 0

    {
        "ok": true
    }

.. note::

Admins may want to bump their ``[mem3] sync_concurrency`` value to a
larger figure for the duration of the shards sync.