1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Memcached response coalescing helpers.
//!
//! When a `get` / `gets` request fans out across shards, the
//! per-shard responses need to be stitched back into a single
//! reply. The reference engine implements this with two helpers:
//! `memcache_pre_coalesce` adjusts each shard response in place to
//! drop the `END` marker, and `memcache_post_coalesce` concatenates
//! the per-shard payloads and appends a single trailing
//! `END\r\n`.
//!
//! This stage builds the data-shape side of those helpers; the
//! mbuf-level wiring that the reactor needs lives next to the
//! Stage 9 connection FSM.
use crate;
/// Adjust `rsp` in place ahead of post-coalesce.
///
/// For `VALUE` and `END` shard responses, the helper records that
/// the trailing `END` marker should be dropped during merge. For
/// any other response on a fragmented request the helper flags the
/// parent request as errored.
///
/// # Examples
///
/// ```
/// use dynomite::msg::{Msg, MsgType};
/// use dynomite::proto::memcache::memcache_pre_coalesce;
///
/// let mut rsp = Msg::new(0, MsgType::RspMcEnd, false);
/// rsp.set_frag_id(1);
/// memcache_pre_coalesce(&mut rsp);
/// // No mbuf side-effects in the data-shape path; the function
/// // returns without panicking.
/// ```
/// Post-coalesce hook for the parent request once every shard
/// response has arrived.
///
/// In the reference engine this concatenates each shard's value
/// payload onto the parent response and writes a single trailing
/// `END\r\n`. The data-shape side is to flag the parent request
/// as fully done; the mbuf-level concatenation lives in Stage 9.
///
/// # Examples
///
/// ```
/// use dynomite::msg::{Msg, MsgType};
/// use dynomite::proto::memcache::memcache_post_coalesce;
///
/// let mut req = Msg::new(0, MsgType::ReqMcGet, true);
/// memcache_post_coalesce(&mut req);
/// // The data-shape path is a no-op when there are no fragments
/// // attached.
/// ```