2121package com .apple .foundationdb .async .hnsw ;
2222
2323import com .apple .foundationdb .ReadTransaction ;
24- import com .apple .foundationdb .Transaction ;
2524import com .apple .foundationdb .subspace .Subspace ;
2625import com .apple .foundationdb .tuple .Tuple ;
2726
2827import javax .annotation .Nonnull ;
2928import javax .annotation .Nullable ;
30- import java .math .BigInteger ;
31- import java .util .List ;
32- import java .util .Objects ;
3329import java .util .concurrent .CompletableFuture ;
34- import java .util .function .Function ;
3530
3631/**
3732 * Implementations and attributes common to all concrete implementations of {@link StorageAdapter}.
@@ -53,8 +48,6 @@ abstract class AbstractStorageAdapter implements StorageAdapter {
5348 private final Subspace dataSubspace ;
5449
5550 protected AbstractStorageAdapter (@ Nonnull final HNSW .Config config , @ Nonnull final Subspace subspace ,
56- @ Nonnull final Subspace nodeSlotIndexSubspace ,
57- @ Nonnull final Function <HNSW .Point , BigInteger > hilbertValueFunction ,
5851 @ Nonnull final OnWriteListener onWriteListener ,
5952 @ Nonnull final OnReadListener onReadListener ) {
6053 this .config = config ;
@@ -108,79 +101,16 @@ public OnReadListener getOnReadListener() {
108101 return onReadListener ;
109102 }
110103
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-
174104 @ Nonnull
175105 @ 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 ,
177107 @ Nonnull final ReadTransaction readTransaction ,
178108 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 );
180110 }
181111
182112 @ 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 ,
184114 @ Nonnull ReadTransaction readTransaction ,
185115 int layer , @ Nonnull Tuple primaryKey );
186116
@@ -197,16 +127,4 @@ protected abstract <N extends NodeReference> CompletableFuture<Node<N>> fetchNod
197127 private <N extends NodeReference > Node <N > checkNode (@ Nullable final Node <N > node ) {
198128 return node ;
199129 }
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 );
212130}
0 commit comments