Skip to content

Commit 3445c3d

Browse files
committed
read and insert path both code complete
1 parent dae05d5 commit 3445c3d

20 files changed

+547
-580
lines changed

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/AbstractChangeSet.java

Lines changed: 0 additions & 94 deletions
This file was deleted.

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/AbstractStorageAdapter.java

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,29 @@
3131
/**
3232
* Implementations and attributes common to all concrete implementations of {@link StorageAdapter}.
3333
*/
34-
abstract class AbstractStorageAdapter implements StorageAdapter {
35-
public static final byte SUBSPACE_PREFIX_ENTRY_NODE = 0x01;
36-
public static final byte SUBSPACE_PREFIX_DATA = 0x02;
37-
34+
abstract class AbstractStorageAdapter<N extends NodeReference> implements StorageAdapter<N> {
3835
@Nonnull
3936
private final HNSW.Config config;
4037
@Nonnull
38+
private final NodeFactory<N> nodeFactory;
39+
@Nonnull
4140
private final Subspace subspace;
4241
@Nonnull
4342
private final OnWriteListener onWriteListener;
4443
@Nonnull
4544
private final OnReadListener onReadListener;
4645

47-
private final Subspace entryNodeSubspace;
4846
private final Subspace dataSubspace;
4947

50-
protected AbstractStorageAdapter(@Nonnull final HNSW.Config config, @Nonnull final Subspace subspace,
48+
protected AbstractStorageAdapter(@Nonnull final HNSW.Config config, @Nonnull final NodeFactory<N> nodeFactory,
49+
@Nonnull final Subspace subspace,
5150
@Nonnull final OnWriteListener onWriteListener,
5251
@Nonnull final OnReadListener onReadListener) {
5352
this.config = config;
53+
this.nodeFactory = nodeFactory;
5454
this.subspace = subspace;
5555
this.onWriteListener = onWriteListener;
5656
this.onReadListener = onReadListener;
57-
58-
this.entryNodeSubspace = subspace.subspace(Tuple.from(SUBSPACE_PREFIX_ENTRY_NODE));
5957
this.dataSubspace = subspace.subspace(Tuple.from(SUBSPACE_PREFIX_DATA));
6058
}
6159

@@ -65,22 +63,22 @@ public HNSW.Config getConfig() {
6563
return config;
6664
}
6765

68-
@Override
6966
@Nonnull
70-
public Subspace getSubspace() {
71-
return subspace;
67+
@Override
68+
public NodeFactory<N> getNodeFactory() {
69+
return nodeFactory;
7270
}
7371

74-
@Nullable
72+
@Nonnull
7573
@Override
76-
public Subspace getSecondarySubspace() {
77-
return null;
74+
public NodeKind getNodeKind() {
75+
return getNodeFactory().getNodeKind();
7876
}
7977

8078
@Override
8179
@Nonnull
82-
public Subspace getEntryNodeSubspace() {
83-
return entryNodeSubspace;
80+
public Subspace getSubspace() {
81+
return subspace;
8482
}
8583

8684
@Override
@@ -103,28 +101,25 @@ public OnReadListener getOnReadListener() {
103101

104102
@Nonnull
105103
@Override
106-
public <N extends NodeReference> CompletableFuture<Node<N>> fetchNode(@Nonnull final NodeFactory<N> nodeFactory,
107-
@Nonnull final ReadTransaction readTransaction,
108-
int layer, @Nonnull Tuple primaryKey) {
109-
return fetchNodeInternal(nodeFactory, readTransaction, layer, primaryKey).thenApply(this::checkNode);
104+
public CompletableFuture<Node<N>> fetchNode(@Nonnull final ReadTransaction readTransaction,
105+
int layer, @Nonnull Tuple primaryKey) {
106+
return fetchNodeInternal(readTransaction, layer, primaryKey).thenApply(this::checkNode);
110107
}
111108

112109
@Nonnull
113-
protected abstract <N extends NodeReference> CompletableFuture<Node<N>> fetchNodeInternal(@Nonnull NodeFactory<N> nodeFactory,
114-
@Nonnull ReadTransaction readTransaction,
115-
int layer, @Nonnull Tuple primaryKey);
110+
protected abstract CompletableFuture<Node<N>> fetchNodeInternal(@Nonnull ReadTransaction readTransaction,
111+
int layer, @Nonnull Tuple primaryKey);
116112

117113
/**
118114
* Method to perform basic invariant check(s) on a newly-fetched node.
119115
*
120116
* @param node the node to check
121-
* @param <N> the type param for the node in order for this method to not be lossy on the type of the node that
122117
* was passed in
123118
*
124119
* @return the node that was passed in
125120
*/
126121
@Nullable
127-
private <N extends NodeReference> Node<N> checkNode(@Nullable final Node<N> node) {
122+
private Node<N> checkNode(@Nullable final Node<N> node) {
128123
return node;
129124
}
130125
}

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/BaseNeighborsChangeSet.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,23 @@
2121
package com.apple.foundationdb.async.hnsw;
2222

2323
import com.apple.foundationdb.Transaction;
24+
import com.apple.foundationdb.tuple.Tuple;
25+
import com.google.common.collect.ImmutableList;
2426

2527
import javax.annotation.Nonnull;
2628
import javax.annotation.Nullable;
2729
import java.util.List;
30+
import java.util.function.Predicate;
2831

2932
/**
3033
* TODO.
3134
*/
3235
class BaseNeighborsChangeSet<N extends NodeReference> implements NeighborsChangeSet<N> {
3336
@Nonnull
34-
private final NodeReferenceAndNode<N> baseNode;
37+
private final List<N> neighbors;
3538

36-
public BaseNeighborsChangeSet(@Nonnull final NodeReferenceAndNode<N> baseNode) {
37-
this.baseNode = baseNode;
39+
public BaseNeighborsChangeSet(@Nonnull final List<N> neighbors) {
40+
this.neighbors = ImmutableList.copyOf(neighbors);
3841
}
3942

4043
@Nullable
@@ -44,10 +47,13 @@ public BaseNeighborsChangeSet<N> getParent() {
4447

4548
@Nonnull
4649
public List<N> merge() {
47-
return baseNode.getNode().getNeighbors();
50+
return neighbors;
4851
}
4952

5053
@Override
51-
public void writeDelta(@Nonnull final Transaction transaction) {
54+
public void writeDelta(@Nonnull final InliningStorageAdapter storageAdapter, @Nonnull final Transaction transaction,
55+
final int layer, @Nonnull final Node<N> node,
56+
@Nonnull final Predicate<Tuple> primaryKeyPredicate) {
57+
// nothing to be written
5258
}
5359
}

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/ByNodeStorageAdapter.java

Lines changed: 0 additions & 108 deletions
This file was deleted.

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/CompactNode.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import com.apple.foundationdb.tuple.Tuple;
2424
import com.christianheina.langx.half4j.Half;
25-
import com.google.common.collect.Lists;
2625

2726
import javax.annotation.Nonnull;
2827
import javax.annotation.Nullable;
@@ -88,25 +87,6 @@ public InliningNode asInliningNode() {
8887
throw new IllegalStateException("this is not an inlining node");
8988
}
9089

91-
@Override
92-
public NodeFactory<NodeReference> sameCreator() {
93-
return CompactNode.factory();
94-
}
95-
96-
@Nonnull
97-
@Override
98-
public Tuple toTuple() {
99-
final List<Object> nodeItems = Lists.newArrayListWithExpectedSize(4);
100-
nodeItems.add(NodeKind.COMPACT.getSerialized());
101-
nodeItems.add(StorageAdapter.tupleFromVector(getVector()));
102-
final List<Tuple> neighborItems = Lists.newArrayListWithExpectedSize(getNeighbors().size());
103-
for (final NodeReference nodeReference : getNeighbors()) {
104-
neighborItems.add(nodeReference.getPrimaryKey());
105-
}
106-
nodeItems.add(Tuple.fromList(neighborItems));
107-
return Tuple.fromList(nodeItems);
108-
}
109-
11090
@Nonnull
11191
public static NodeFactory<NodeReference> factory() {
11292
return FACTORY;

0 commit comments

Comments
 (0)