Skip to content

Commit 0a4b282

Browse files
committed
added logging
1 parent 3445c3d commit 0a4b282

File tree

16 files changed

+411
-43
lines changed

16 files changed

+411
-43
lines changed

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

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

2323
import com.apple.foundationdb.ReadTransaction;
24+
import com.apple.foundationdb.Transaction;
2425
import com.apple.foundationdb.subspace.Subspace;
2526
import com.apple.foundationdb.tuple.Tuple;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2629

2730
import javax.annotation.Nonnull;
2831
import javax.annotation.Nullable;
@@ -32,6 +35,9 @@
3235
* Implementations and attributes common to all concrete implementations of {@link StorageAdapter}.
3336
*/
3437
abstract class AbstractStorageAdapter<N extends NodeReference> implements StorageAdapter<N> {
38+
@Nonnull
39+
private static final Logger logger = LoggerFactory.getLogger(AbstractStorageAdapter.class);
40+
3541
@Nonnull
3642
private final HNSW.Config config;
3743
@Nonnull
@@ -122,4 +128,16 @@ protected abstract CompletableFuture<Node<N>> fetchNodeInternal(@Nonnull ReadTra
122128
private Node<N> checkNode(@Nullable final Node<N> node) {
123129
return node;
124130
}
131+
132+
public void writeNode(@Nonnull Transaction transaction, @Nonnull Node<N> node, int layer,
133+
@Nonnull NeighborsChangeSet<N> changeSet) {
134+
writeNodeInternal(transaction, node, layer, changeSet);
135+
if (logger.isDebugEnabled()) {
136+
logger.debug("written node with key={} at layer={}", node.getPrimaryKey(), layer);
137+
}
138+
}
139+
140+
protected abstract void writeNodeInternal(@Nonnull Transaction transaction, @Nonnull Node<N> node, int layer,
141+
@Nonnull NeighborsChangeSet<N> changeSet);
142+
125143
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public NodeKind getNodeKind() {
5353
private final Vector<Half> vector;
5454

5555
public CompactNode(@Nonnull final Tuple primaryKey, @Nonnull final Vector<Half> vector,
56-
@Nonnull final List<NodeReference> nodeReferences) {
57-
super(primaryKey, nodeReferences);
56+
@Nonnull final List<NodeReference> neighbors) {
57+
super(primaryKey, neighbors);
5858
this.vector = vector;
5959
}
6060

@@ -91,4 +91,11 @@ public InliningNode asInliningNode() {
9191
public static NodeFactory<NodeReference> factory() {
9292
return FACTORY;
9393
}
94+
95+
@Override
96+
public String toString() {
97+
return "C[primaryKey=" + getPrimaryKey() +
98+
";vector=" + vector +
99+
";neighbors=" + getNeighbors() + "]";
100+
}
94101
}

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.christianheina.langx.half4j.Half;
2828
import com.google.common.base.Verify;
2929
import com.google.common.collect.Lists;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3032

3133
import javax.annotation.Nonnull;
3234
import java.util.List;
@@ -36,6 +38,9 @@
3638
* TODO.
3739
*/
3840
class CompactStorageAdapter extends AbstractStorageAdapter<NodeReference> implements StorageAdapter<NodeReference> {
41+
@Nonnull
42+
private static final Logger logger = LoggerFactory.getLogger(CompactStorageAdapter.class);
43+
3944
public CompactStorageAdapter(@Nonnull final HNSW.Config config, @Nonnull final NodeFactory<NodeReference> nodeFactory,
4045
@Nonnull final Subspace subspace,
4146
@Nonnull final OnWriteListener onWriteListener,
@@ -98,8 +103,8 @@ private Node<NodeReference> compactNodeFromTuples(@Nonnull final Tuple primaryKe
98103
final Vector<Half> vector = StorageAdapter.vectorFromTuple(vectorTuple);
99104
final List<NodeReference> nodeReferences = Lists.newArrayListWithExpectedSize(neighborsTuple.size());
100105

101-
for (final Object neighborObject : neighborsTuple) {
102-
final Tuple neighborTuple = (Tuple)neighborObject;
106+
for (int i = 0; i < neighborsTuple.size(); i ++) {
107+
final Tuple neighborTuple = neighborsTuple.getNestedTuple(i);
103108
nodeReferences.add(new NodeReference(neighborTuple));
104109
}
105110

@@ -108,11 +113,11 @@ private Node<NodeReference> compactNodeFromTuples(@Nonnull final Tuple primaryKe
108113

109114

110115
@Override
111-
public void writeNode(@Nonnull final Transaction transaction, @Nonnull final Node<NodeReference> node,
112-
final int layer, @Nonnull final NeighborsChangeSet<NodeReference> neighborsChangeSet) {
116+
public void writeNodeInternal(@Nonnull final Transaction transaction, @Nonnull final Node<NodeReference> node,
117+
final int layer, @Nonnull final NeighborsChangeSet<NodeReference> neighborsChangeSet) {
113118
final byte[] key = getDataSubspace().pack(Tuple.from(layer, node.getPrimaryKey()));
114119

115-
final List<Object> nodeItems = Lists.newArrayListWithExpectedSize(4);
120+
final List<Object> nodeItems = Lists.newArrayListWithExpectedSize(3);
116121
nodeItems.add(NodeKind.COMPACT.getSerialized());
117122
final CompactNode compactNode = node.asCompactNode();
118123
nodeItems.add(StorageAdapter.tupleFromVector(compactNode.getVector()));
@@ -123,6 +128,11 @@ public void writeNode(@Nonnull final Transaction transaction, @Nonnull final Nod
123128
for (final NodeReference neighborReference : neighbors) {
124129
neighborItems.add(neighborReference.getPrimaryKey());
125130
}
131+
if (logger.isDebugEnabled()) {
132+
logger.debug("written neighbors of primaryKey={}, oldSize={}, newSize={}", node.getPrimaryKey(),
133+
node.getNeighbors().size(), neighborItems.size());
134+
}
135+
126136
nodeItems.add(Tuple.fromList(neighborItems));
127137
final Tuple nodeTuple = Tuple.fromList(nodeItems);
128138

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import com.apple.foundationdb.tuple.Tuple;
2525
import com.google.common.collect.ImmutableSet;
2626
import com.google.common.collect.Iterables;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2729

2830
import javax.annotation.Nonnull;
2931
import java.util.Collection;
@@ -34,6 +36,9 @@
3436
* TODO.
3537
*/
3638
class DeleteNeighborsChangeSet<N extends NodeReference> implements NeighborsChangeSet<N> {
39+
@Nonnull
40+
private static final Logger logger = LoggerFactory.getLogger(DeleteNeighborsChangeSet.class);
41+
3742
@Nonnull
3843
private final NeighborsChangeSet<N> parent;
3944

@@ -66,6 +71,10 @@ public void writeDelta(@Nonnull final InliningStorageAdapter storageAdapter, @No
6671
for (final Tuple deletedNeighborPrimaryKey : deletedNeighborsPrimaryKeys) {
6772
if (tuplePredicate.test(deletedNeighborPrimaryKey)) {
6873
storageAdapter.deleteNeighbor(transaction, layer, node.asInliningNode(), deletedNeighborPrimaryKey);
74+
if (logger.isDebugEnabled()) {
75+
logger.debug("deleted neighbor of primaryKey={} targeting primaryKey={}", node.getPrimaryKey(),
76+
deletedNeighborPrimaryKey);
77+
}
6978
}
7079
}
7180
}

0 commit comments

Comments
 (0)