21
21
package com .apple .foundationdb .async .hnsw ;
22
22
23
23
import com .apple .foundationdb .ReadTransaction ;
24
- import com .apple .foundationdb .Transaction ;
25
24
import com .apple .foundationdb .subspace .Subspace ;
26
25
import com .apple .foundationdb .tuple .Tuple ;
27
26
28
27
import javax .annotation .Nonnull ;
29
28
import javax .annotation .Nullable ;
30
- import java .math .BigInteger ;
31
- import java .util .List ;
32
- import java .util .Objects ;
33
29
import java .util .concurrent .CompletableFuture ;
34
- import java .util .function .Function ;
35
30
36
31
/**
37
32
* Implementations and attributes common to all concrete implementations of {@link StorageAdapter}.
@@ -53,8 +48,6 @@ abstract class AbstractStorageAdapter implements StorageAdapter {
53
48
private final Subspace dataSubspace ;
54
49
55
50
protected AbstractStorageAdapter (@ Nonnull final HNSW .Config config , @ Nonnull final Subspace subspace ,
56
- @ Nonnull final Subspace nodeSlotIndexSubspace ,
57
- @ Nonnull final Function <HNSW .Point , BigInteger > hilbertValueFunction ,
58
51
@ Nonnull final OnWriteListener onWriteListener ,
59
52
@ Nonnull final OnReadListener onReadListener ) {
60
53
this .config = config ;
@@ -108,79 +101,16 @@ public OnReadListener getOnReadListener() {
108
101
return onReadListener ;
109
102
}
110
103
111
- @ Override
112
- public void writeNodes (@ Nonnull final Transaction transaction , @ Nonnull final List <? extends Node > nodes ) {
113
- for (final Node node : nodes ) {
114
- writeNode (transaction , node );
115
- }
116
- }
117
-
118
- protected void writeNode (@ Nonnull final Transaction transaction , @ Nonnull final Node node ) {
119
- final Node .ChangeSet changeSet = node .getChangeSet ();
120
- if (changeSet == null ) {
121
- return ;
122
- }
123
-
124
- changeSet .apply (transaction );
125
- getOnWriteListener ().onNodeWritten (node );
126
- }
127
-
128
- @ Nonnull
129
- public byte [] packWithSubspace (final byte [] key ) {
130
- return getSubspace ().pack (key );
131
- }
132
-
133
- @ Nonnull
134
- public byte [] packWithSubspace (final Tuple tuple ) {
135
- return getSubspace ().pack (tuple );
136
- }
137
-
138
- @ Nonnull
139
- @ Override
140
- public CompletableFuture <Node > scanNodeIndexAndFetchNode (@ Nonnull final ReadTransaction transaction ,
141
- final int level ,
142
- @ Nonnull final BigInteger hilbertValue ,
143
- @ Nonnull final Tuple key ,
144
- final boolean isInsertUpdate ) {
145
- Objects .requireNonNull (nodeSlotIndexAdapter );
146
- return nodeSlotIndexAdapter .scanIndexForNodeId (transaction , level , hilbertValue , key , isInsertUpdate )
147
- .thenCompose (nodeId -> nodeId == null
148
- ? CompletableFuture .completedFuture (null )
149
- : fetchNode (transaction , nodeId ));
150
- }
151
-
152
- @ Override
153
- public void insertIntoNodeIndexIfNecessary (@ Nonnull final Transaction transaction , final int level ,
154
- @ Nonnull final NodeSlot nodeSlot ) {
155
- if (!getConfig ().isUseNodeSlotIndex () || !(nodeSlot instanceof ChildSlot )) {
156
- return ;
157
- }
158
-
159
- Objects .requireNonNull (nodeSlotIndexAdapter );
160
- nodeSlotIndexAdapter .writeChildSlot (transaction , level , (ChildSlot )nodeSlot );
161
- }
162
-
163
- @ Override
164
- public void deleteFromNodeIndexIfNecessary (@ Nonnull final Transaction transaction , final int level ,
165
- @ Nonnull final NodeSlot nodeSlot ) {
166
- if (!getConfig ().isUseNodeSlotIndex () || !(nodeSlot instanceof ChildSlot )) {
167
- return ;
168
- }
169
-
170
- Objects .requireNonNull (nodeSlotIndexAdapter );
171
- nodeSlotIndexAdapter .clearChildSlot (transaction , level , (ChildSlot )nodeSlot );
172
- }
173
-
174
104
@ Nonnull
175
105
@ Override
176
- public <N extends NodeReference > CompletableFuture <Node <N >> fetchNode (@ Nonnull final Node . NodeCreator <N > creator ,
106
+ public <N extends NodeReference > CompletableFuture <Node <N >> fetchNode (@ Nonnull final NodeFactory <N > nodeFactory ,
177
107
@ Nonnull final ReadTransaction readTransaction ,
178
108
int layer , @ Nonnull Tuple primaryKey ) {
179
- return fetchNodeInternal (creator , readTransaction , layer , primaryKey ).thenApply (this ::checkNode );
109
+ return fetchNodeInternal (nodeFactory , readTransaction , layer , primaryKey ).thenApply (this ::checkNode );
180
110
}
181
111
182
112
@ Nonnull
183
- protected abstract <N extends NodeReference > CompletableFuture <Node <N >> fetchNodeInternal (@ Nonnull Node . NodeCreator <N > creator ,
113
+ protected abstract <N extends NodeReference > CompletableFuture <Node <N >> fetchNodeInternal (@ Nonnull NodeFactory <N > nodeFactory ,
184
114
@ Nonnull ReadTransaction readTransaction ,
185
115
int layer , @ Nonnull Tuple primaryKey );
186
116
@@ -197,16 +127,4 @@ protected abstract <N extends NodeReference> CompletableFuture<Node<N>> fetchNod
197
127
private <N extends NodeReference > Node <N > checkNode (@ Nullable final Node <N > node ) {
198
128
return node ;
199
129
}
200
-
201
- @ Nonnull
202
- abstract <S extends NodeSlot , N extends AbstractNode <S , N >> AbstractChangeSet <S , N >
203
- newInsertChangeSet (@ Nonnull N node , int level , @ Nonnull List <S > insertedSlots );
204
-
205
- @ Nonnull
206
- abstract <S extends NodeSlot , N extends AbstractNode <S , N >> AbstractChangeSet <S , N >
207
- newUpdateChangeSet (@ Nonnull N node , int level , @ Nonnull S originalSlot , @ Nonnull S updatedSlot );
208
-
209
- @ Nonnull
210
- abstract <S extends NodeSlot , N extends AbstractNode <S , N >> AbstractChangeSet <S , N >
211
- newDeleteChangeSet (@ Nonnull N node , int level , @ Nonnull List <S > deletedSlots );
212
130
}
0 commit comments