forked from couchbase/gocbcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcp.go
234 lines (202 loc) · 6.51 KB
/
dcp.go
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package gocbcore
// OpenStreamFilterOptions are the filtering options available to the OpenStream operation.
type OpenStreamFilterOptions struct {
ScopeID uint32
CollectionIDs []uint32
}
// OpenStreamStreamOptions are the stream options available to the OpenStream operation.
type OpenStreamStreamOptions struct {
StreamID uint16
}
// OpenStreamManifestOptions are the manifest options available to the OpenStream operation.
type OpenStreamManifestOptions struct {
ManifestUID uint64
}
// OpenStreamOptions are the options available to the OpenStream operation.
type OpenStreamOptions struct {
FilterOptions *OpenStreamFilterOptions
StreamOptions *OpenStreamStreamOptions
ManifestOptions *OpenStreamManifestOptions
}
// GetVbucketSeqnoFilterOptions are the filter options available to the GetVbucketSeqno operation.
type GetVbucketSeqnoFilterOptions struct {
CollectionID uint32
}
// GetVbucketSeqnoOptions are the options available to the GetVbucketSeqno operation.
type GetVbucketSeqnoOptions struct {
FilterOptions *GetVbucketSeqnoFilterOptions
}
// CloseStreamStreamOptions are the stream options available to the CloseStream operation.
type CloseStreamStreamOptions struct {
StreamID uint16
}
// CloseStreamOptions are the options available to the CloseStream operation.
type CloseStreamOptions struct {
StreamOptions *CloseStreamStreamOptions
}
// SnapshotState represents the state of a particular cluster snapshot.
type SnapshotState uint32
// HasInMemory returns whether this snapshot is available in memory.
func (s SnapshotState) HasInMemory() bool {
return uint32(s)&1 != 0
}
// HasOnDisk returns whether this snapshot is available on disk.
func (s SnapshotState) HasOnDisk() bool {
return uint32(s)&2 != 0
}
// FailoverEntry represents a single entry in the server fail-over log.
type FailoverEntry struct {
VbUUID VbUUID
SeqNo SeqNo
}
// DcpSnapshotMarker represents a single response from the server
type DcpSnapshotMarker struct {
StartSeqNo, EndSeqNo uint64
VbID, StreamID uint16
SnapshotType SnapshotState
MaxVisibleSeqNo, HighCompletedSeqNo, SnapshotTimeStamp uint64
}
// DcpMutation represents a single DCP mutation from the server
type DcpMutation struct {
SeqNo, RevNo uint64
Cas uint64
Flags, Expiry, LockTime uint32
CollectionID uint32
VbID uint16
StreamID uint16
Datatype uint8
Key, Value []byte
}
// DcpDeletion represents a single DCP deletion from the server
type DcpDeletion struct {
SeqNo, RevNo uint64
Cas uint64
DeleteTime uint32
CollectionID uint32
VbID uint16
StreamID uint16
Datatype uint8
Key, Value []byte
}
// DcpExpiration represents a single DCP expiration from the server
type DcpExpiration struct {
SeqNo, RevNo uint64
Cas uint64
DeleteTime uint32
CollectionID uint32
VbID uint16
StreamID uint16
Key []byte
}
// DcpCollectionCreation represents a collection create DCP event from the server
type DcpCollectionCreation struct {
SeqNo uint64
Version uint8
VbID uint16
ManifestUID uint64
ScopeID uint32
CollectionID uint32
Ttl uint32
StreamID uint16
Key []byte
}
// DcpCollectionDeleteion represents a collection delete DCP event from the server
type DcpCollectionDeletion struct {
SeqNo uint64
ManifestUID uint64
ScopeID uint32
CollectionID uint32
StreamID uint16
VbID uint16
Version uint8
}
// DcpCollectionFlush represents a collection flush DCP event from the server
type DcpCollectionFlush struct {
SeqNo uint64
Version uint8
VbID uint16
ManifestUID uint64
CollectionID uint32
StreamID uint16
}
// DcpScopeCreation represents a scope creation DCP event from the server
type DcpScopeCreation struct {
SeqNo uint64
Version uint8
VbID uint16
ManifestUID uint64
ScopeID uint32
StreamID uint16
Key []byte
}
// DcpScopeDeletion represents a scope Deletion DCP event from the server
type DcpScopeDeletion struct {
SeqNo uint64
Version uint8
VbID uint16
ManifestUID uint64
ScopeID uint32
StreamID uint16
}
// DcpCollectionModification represents a DCP collection modify event from the server
type DcpCollectionModification struct {
SeqNo uint64
ManifestUID uint64
CollectionID uint32
Ttl uint32
VbID uint16
StreamID uint16
Version uint8
}
// DcpOSOSnapshot reprensents a DCP OSSSnapshot from the server
type DcpOSOSnapshot struct {
SnapshotType uint32
VbID uint16
StreamID uint16
}
// DcpSeqNoAdvanced represents a DCP SeqNoAdvanced from the server
type DcpSeqNoAdvanced struct {
SeqNo uint64
VbID uint16
StreamID uint16
}
// DcpStreamEnd represnets a DCP stream end from the server
type DcpStreamEnd struct {
VbID uint16
StreamID uint16
}
// StreamObserver provides an interface to receive events from a running DCP stream.
type StreamObserver interface {
SnapshotMarker(snapshotMarker DcpSnapshotMarker)
Mutation(mutation DcpMutation)
Deletion(deletion DcpDeletion)
Expiration(expiration DcpExpiration)
End(end DcpStreamEnd, err error)
CreateCollection(creation DcpCollectionCreation)
DeleteCollection(deletion DcpCollectionDeletion)
FlushCollection(flush DcpCollectionFlush)
CreateScope(creation DcpScopeCreation)
DeleteScope(deletion DcpScopeDeletion)
ModifyCollection(modification DcpCollectionModification)
OSOSnapshot(snapshot DcpOSOSnapshot)
SeqNoAdvanced(seqNoAdvanced DcpSeqNoAdvanced)
}
type streamFilter struct {
ManifestUID string `json:"uid,omitempty"`
Collections []string `json:"collections,omitempty"`
Scope string `json:"scope,omitempty"`
StreamID uint16 `json:"sid,omitempty"`
}
// OpenStreamCallback is invoked with the results of `OpenStream` operations.
type OpenStreamCallback func([]FailoverEntry, error)
// CloseStreamCallback is invoked with the results of `CloseStream` operations.
type CloseStreamCallback func(error)
// GetFailoverLogCallback is invoked with the results of `GetFailoverLog` operations.
type GetFailoverLogCallback func([]FailoverEntry, error)
// VbSeqNoEntry represents a single GetVbucketSeqnos sequence number entry.
type VbSeqNoEntry struct {
VbID uint16
SeqNo SeqNo
}
// GetVBucketSeqnosCallback is invoked with the results of `GetVBucketSeqnos` operations.
type GetVBucketSeqnosCallback func([]VbSeqNoEntry, error)