1% Licensed under the Apache License, Version 2.0 (the "License"); you may not
2% use this file except in compliance with the License. You may obtain a copy of
3% the License at
4%
5%   http://www.apache.org/licenses/LICENSE-2.0
6%
7% Unless required by applicable law or agreed to in writing, software
8% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10% License for the specific language governing permissions and limitations under
11% the License.
12
13-define(DCP_HEADER_LEN, 24).
14
15-define(DCP_MAGIC_REQUEST, 16#80).
16-define(DCP_MAGIC_RESPONSE, 16#81).
17-define(DCP_OPCODE_OPEN_CONNECTION, 16#50).
18-define(DCP_OPCODE_STREAM_REQUEST, 16#53).
19-define(DCP_OPCODE_STREAM_CLOSE, 16#52).
20-define(DCP_OPCODE_FAILOVER_LOG_REQUEST, 16#54).
21-define(DCP_OPCODE_STREAM_END, 16#55).
22-define(DCP_OPCODE_SNAPSHOT_MARKER, 16#56).
23-define(DCP_OPCODE_MUTATION, 16#57).
24-define(DCP_OPCODE_DELETION, 16#58).
25-define(DCP_OPCODE_EXPIRATION, 16#59).
26-define(DCP_OPCODE_STATS, 16#10).
27-define(DCP_OPCODE_SEQS, 16#48).
28-define(DCP_OPCODE_SASL_AUTH, 16#21).
29-define(DCP_OPCODE_SELECT_BUCKET, 16#89).
30-define(DCP_OPCODE_DCP_CONTROL, 16#5E).
31-define(DCP_OPCODE_DCP_BUFFER, 16#5D).
32-define(DCP_OPCODE_DCP_NOOP, 16#5C).
33-define(DCP_FLAG_OK, 16#00).
34-define(DCP_FLAG_STATE_CHANGED, 16#01).
35-define(DCP_FLAG_CONSUMER, 16#00).
36-define(DCP_FLAG_PRODUCER, 16#01).
37-define(DCP_FLAG_NOFLAG, 16#00).
38-define(DCP_FLAG_DISKONLY, 16#02).
39-define(DCP_FLAG_USELATEST_ENDSEQNO, 16#04).
40-define(DCP_REQUEST_TYPE_MUTATION, 16#03).
41-define(DCP_REQUEST_TYPE_DELETION, 16#04).
42-define(DCP_STATUS_OK, 16#00).
43-define(DCP_STATUS_KEY_NOT_FOUND, 16#01).
44-define(DCP_STATUS_KEY_EEXISTS, 16#02).
45-define(DCP_STATUS_ROLLBACK, 16#23).
46-define(DCP_STATUS_NOT_MY_VBUCKET, 16#07).
47-define(DCP_STATUS_ERANGE, 16#22).
48-define(DCP_STATUS_SASL_AUTH_FAILED, 16#20).
49-define(DCP_STATUS_NOT_SUPPORTED, 16#83).
50-define(DCP_STATUS_TMP_FAIL, 16#86).
51-define(DCP_SNAPSHOT_TYPE_MEMORY, 16#1).
52-define(DCP_SNAPSHOT_TYPE_DISK, 16#2).
53-define(DCP_SNAPSHOT_TYPE_MASK, 16#3).
54-define(DCP_DATA_TYPE_RAW, 16#0).
55-define(DCP_DATA_TYPE_JSON, 16#1).
56-define(DCP_DATA_TYPE_RAW_COMPRESSED, 16#2).
57-define(DCP_DATA_TYPE_JSON_COMPRESSED, 16#3).
58% The sizes are in bits
59-define(DCP_SIZES_KEY_LENGTH, 16).
60-define(DCP_SIZES_PARTITION, 16).
61-define(DCP_SIZES_BODY, 32).
62-define(DCP_SIZES_OPAQUE, 32).
63-define(DCP_SIZES_CAS, 64).
64-define(DCP_SIZES_BY_SEQ, 64).
65-define(DCP_SIZES_REV_SEQ, 64).
66-define(DCP_SIZES_FLAGS, 32).
67-define(DCP_SIZES_EXPIRATION, 32).
68-define(DCP_SIZES_LOCK, 32).
69-define(DCP_SIZES_KEY, 40).
70-define(DCP_SIZES_VALUE, 56).
71-define(DCP_SIZES_PARTITION_UUID, 64).
72-define(DCP_SIZES_RESERVED, 32).
73-define(DCP_SIZES_STATUS, 16).
74-define(DCP_SIZES_SEQNO, 32).
75-define(DCP_SIZES_METADATA_LENGTH, 16).
76-define(DCP_SIZES_NRU_LENGTH, 8).
77-define(DCP_SIZES_SNAPSHOT_TYPE, 32).
78-define(DCP_SIZES_BUFFER_SIZE, 32).
79-define(DCP_BUFFER_ACK_THRESHOLD, 0.2).
80
81% NOTE vmx 2014-01-16: In ep-engine the maximum size is currently 25
82-define(DCP_MAX_FAILOVER_LOG_SIZE, 25).
83
84
85-record(mutation, {
86    seq = 0         :: update_seq(),
87    rev_seq = 0     :: non_neg_integer(),
88    flags = 0       :: non_neg_integer(),
89    expiration = 0  :: non_neg_integer(),
90    locktime = 0    :: non_neg_integer(),
91    key = <<>>      :: binary(),
92    value = <<>>    :: binary(),
93    metadata = <<>> :: binary()
94}).
95
96-record(dcp_doc, {
97    id = <<>>       :: binary(),
98    body = <<>>     :: binary(),
99    % data_type corresponds to content_meta in #doc{} from couch_db.hrl
100    data_type = 0   :: 0..255,
101    partition = 0   :: partition_id(),
102    cas = 0         :: uint64(),
103    rev_seq = 0     :: uint64(),
104    seq = 0         :: update_seq(),
105    flags = 0       :: non_neg_integer(),
106    expiration = 0  :: non_neg_integer(),
107    deleted = false :: boolean()
108}).
109