forked from FoundationDB/fdb-record-layer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BloomFilterCursorContinuation.java
105 lines (92 loc) · 3.21 KB
/
BloomFilterCursorContinuation.java
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
/*
* BloomFilterCursorContinuation.java
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2015-2019 Apple Inc. and the FoundationDB project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.apple.foundationdb.record.provider.foundationdb.cursors;
import com.apple.foundationdb.record.RecordCursorContinuation;
import com.google.protobuf.ByteString;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static com.apple.foundationdb.record.RecordCursorProto.ProbableIntersectionContinuation;
class BloomFilterCursorContinuation implements RecordCursorContinuation {
@Nonnull
private final RecordCursorContinuation childContinuation;
@Nullable
private final ByteString bloomBytes;
@Nullable
private ProbableIntersectionContinuation.CursorState cachedProto;
@Nullable
private byte[] cachedBytes;
@Nullable
private ByteString cachedByteString;
BloomFilterCursorContinuation(@Nonnull RecordCursorContinuation childContinuation, @Nullable ByteString bloomBytes) {
this.childContinuation = childContinuation;
this.bloomBytes = bloomBytes;
}
@Nonnull
ProbableIntersectionContinuation.CursorState toProto() {
if (cachedProto == null) {
ProbableIntersectionContinuation.CursorState.Builder builder = ProbableIntersectionContinuation.CursorState.newBuilder();
if (childContinuation.isEnd()) {
builder.setExhausted(true);
} else {
ByteString childBytes = childContinuation.toByteString();
if (!childBytes.isEmpty()) {
builder.setContinuation(childBytes);
}
}
if (bloomBytes != null) {
builder.setBloomFilter(bloomBytes);
}
cachedProto = builder.build();
}
return cachedProto;
}
@Override
@Nullable
public byte[] toBytes() {
if (cachedBytes == null) {
cachedBytes = toByteString().toByteArray();
}
return cachedBytes;
}
@Override
@Nonnull
public ByteString toByteString() {
if (cachedByteString == null) {
cachedByteString = toProto().toByteString();
}
return cachedByteString;
}
@Nonnull
RecordCursorContinuation getChild() {
return childContinuation;
}
@Nullable
ByteString getBloomBytes() {
return bloomBytes;
}
// Bloom continuations can never themselves be end continuations, though their children might be.
@Override
public boolean isEnd() {
return false;
}
boolean isChildEnd() {
return childContinuation.isEnd();
}
}