注意

本文档适用于 Ceph 开发版本。

网络协议

本文件描述了 Ceph 使用的网络协议。为了理解结构的定义方式,建议先阅读介绍。网络编码第一部分。

Hello

协议以握手开始,确认两个节点都在与 Ceph 通信,并共享一些基本信息。

连接

一旦横幅得到验证并且地址交换完毕,连接协商就开始了。首先客户端发送一个ceph_msg_connect结构,包含其信息。

// From src/include/msgr.h
struct ceph_msg_connect {
        u64le features;            // Supported features (CEPH_FEATURE_*)
        u32le host_type;           // CEPH_ENTITY_TYPE_*
        u32le global_seq;          // Number of connections initiated by this host.
        u32le connect_seq;         // Number of connections initiated in this session.
        u32le protocol_version;
        u32le authorizer_protocol;
        u32le authorizer_len;
        u8    flags;               // CEPH_MSG_CONNECT_*
        u8    authorizer[authorizer_len];
}

连接回复

一旦发送了连接请求,连接实际上就已经打开了,但是服务器发送的第一个消息必须是连接回复消息。

struct ceph_msg_connect_reply {
        u8    tag; // Tag indicating response code.
        u64le features;
        u32le global_seq;
        u32le connect_seq;
        u32le protocol_version;
        u32le authorizer_len;
        u8    flags;
        u8    authorizer[authorizer_len];
}

MSGR 协议

这是一种低级协议,消息通过它进行传递。在这个级别的消息由一个标记字节组成,用于识别消息类型,然后是消息数据。

// Virtual structure.
struct {
        u8 tag; // CEPH_MSGR_TAG_*
        u8 data[]; // Length depends on tag and data.
}

消息的长度由标记字节决定,并且根据data数组本身中的信息,取决于消息类型。data如果你不知道消息的类型,就无法确定消息的长度。

Note

消息标签定义在

CEPH_MSGR_TAG_CLOSE (0x06)src/include/msgr.h中,当前的标签列在下表中,并附带了它们包含的数据。请注意,定义的结构在源代码中不存在,它们只是为了表示协议。

CEPH_MSGR_TAG_CLOSE (0x06)

struct ceph_msgr_close {
        u8 tag = 0x06;
        u8 data[0]; // No data.
}

关闭消息表示连接正在关闭。

CEPH_MSGR_TAG_MSG (0x07)

struct ceph_msgr_msg {
        u8 tag = 0x07;
        ceph_msg_header header;
        u8 front [header.front_len ];
        u8 middle[header.middle_len];
        u8 data  [header.data_len  ];
        ceph_msg_footer footer;
}

// From src/include/msgr.h
struct ceph_msg_header {
        u64le seq;       // Sequence number.
        u64le tid;       // Transaction ID.
        u16le type;      // Message type (CEPH_MSG_* or MSG_*).
        u16le priority;  // Priority (higher is more important).
        u16le version;   // Version of message encoding.

        u32le front_len;  // The size of the front section.
        u32le middle_len; // The size of the middle section.
        u32le data_len;   // The size of the data section.
        u16le data_off;   // The way data should be aligned by the receiver.

        ceph_entity_name src; // Information about the sender.

        u16le compat_version; // Oldest compatible encoding version.
        u16le reserved;       // Unused.
        u32le crc;            // CRC of header.
}

// From src/include/msgr.h
struct ceph_msg_footer {
        u32le front_crc;  // Checksums of the various sections.
        u32le middle_crc; //
        u32le data_crc;   //
        u64le sig; // Cryptographic signature.
        u8    flags;
}

消息是 Ceph 的业务逻辑。它们是用于在节点之间发送数据和请求的东西。消息头包含消息的长度,以便可以优雅地处理未知消息。

消息类型常量有两个名称CEPH_MSG_*MSG_*。这两个名称之间的唯一区别是第一个被认为是“公开”的,而第二个仅用于内部使用。在协议级别没有区别。

CEPH_MSGR_TAG_ACK (0x08)

struct ceph_msgr_ack {
        u8    tag = 0x08;
        u64le seq; // The sequence number of the message being acknowledged.
}

CEPH_MSGR_TAG_KEEPALIVE (0x09)

struct ceph_msgr_keepalive {
        u8 tag = 0x09;
        u8 data[0]; // No data.
}

CEPH_MSGR_TAG_KEEPALIVE2 (0x0E)

struct ceph_msgr_keepalive2 {
        u8      tag = 0x0E;
        utime_t timestamp;
}

CEPH_MSGR_TAG_KEEPALIVE2_ACK (0x0F)

struct ceph_msgr_keepalive2_ack {
        u8      tag = 0x0F;
        utime_t timestamp;
}

由 Ceph 基金会带给您

Ceph 文档是一个社区资源,由非盈利的 Ceph 基金会资助和托管Ceph Foundation. 如果您想支持这一点和我们的其他工作,请考虑加入现在加入.