Skip to content

DOCS-14429 add missing opcompressed wire protocol #5361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 97 additions & 2 deletions source/reference/mongodb-wire-protocol.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Request Opcodes
The following are the supported ``opCode``:

.. list-table::
:widths: 15 20 65
:widths: 25 10 65
:header-rows: 1

* - Opcode Name
Expand Down Expand Up @@ -178,6 +178,9 @@ The following are the supported ``opCode``:
* - ``OP_COMMANDREPLY``
- 2011
- Cluster internal protocol representing a reply to an ``OP_COMMAND``.
* - ``OP_COMPRESSED``
- 2012
- Wraps other opcodes using compression
* - ``OP_MSG``
- 2013
- Send a message using the format introduced in MongoDB 3.6.
Expand Down Expand Up @@ -622,7 +625,6 @@ If a cursor is read until exhausted (read until :ref:`OP_QUERY <wire-op-query>`
or :ref:`OP_GET_MORE <wire-op-get-more>` returns zero
for the cursor id), there is no need to kill the cursor.


.. _wire-op-command:

OP_COMMAND
Expand Down Expand Up @@ -693,6 +695,99 @@ as a response to a ``OP_COMMAND``.
commands that can require a large amount of data sent from the client,
such as a batch insert.

.. _wire-op-compressed:

OP_COMPRESSED
~~~~~~~~~~~~~

.. versionadded:: MongoDB 3.4

Any opcode can be compressed and wrapped in an OP_COMPRESSED header.
The OP_COMPRESSED message contains the original compressed opcode
message alongside the metadata necessary to process and decompress it.

The format of the OP_COMPRESSED message is:

.. code-block:: bash

struct {
MsgHeader header; // standard message header
int32 originalOpcode; // value of wrapped opcode
int32 uncompressedSize; // size of deflated compressedMessage, excluding MsgHeader
uint8 compressorId; // ID of compressor that compressed message
char *compressedMessage; // opcode itself, excluding MsgHeader
}

.. list-table::
:widths: 25 75
:header-rows: 1

* - Field
- Description

* - ``MsgHeader``

- Message header, as described in :ref:`wp-message-header`.

* - ``originalOpcode``

- Contains the value of the wrapped opcode.

* - ``uncompressedSize``

- The size of the deflated ``compressedMessage``, which excludes
the ``MsgHeader``.

* - ``compressorId``

- The ID of the compressor that compressed the message. A list of
``compressorId`` values is provided below.

* - ``compressedMessage``

- The opcode itself, excluding the ``MsgHeader``.

Each compressor is assigned a predefined compressor ID as follows:

.. list-table::
:widths: 15 25 60
:header-rows: 1

* - compressorId
- Handshake Value
- Description

* - ``0``

- noop

- The content of the message is uncompressed. This is used for
testing.

* - ``1``

- snappy

- The content of the message is compressed using snappy.

* - ``2``

- zlib

- The content of the message is compressed using zlib.

* - ``3``

- zstd

- The content of the message is compressed using zstd.

* - ``4-255``

- reserved

- Reserved for future use.

.. _wire-op-msg:

OP_MSG
Expand Down