You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2015/10/16 10:32:53 UTC

svn commit: r1708913 - in /lucene/dev/branches/lucene6825/lucene/core/src: java/org/apache/lucene/util/bkd/ test/org/apache/lucene/util/bkd/

Author: mikemccand
Date: Fri Oct 16 08:32:53 2015
New Revision: 1708913

URL: http://svn.apache.org/viewvc?rev=1708913&view=rev
Log:
LUCENE-6825: cutover to Directory API, fix some bugs

Modified:
    lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/BKDUtil.java
    lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
    lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/HeapPointWriter.java
    lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointReader.java
    lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java
    lucene/dev/branches/lucene6825/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java

Modified: lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/BKDUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/BKDUtil.java?rev=1708913&r1=1708912&r2=1708913&view=diff
==============================================================================
--- lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/BKDUtil.java (original)
+++ lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/BKDUtil.java Fri Oct 16 08:32:53 2015
@@ -1,5 +1,7 @@
 package org.apache.lucene.util.bkd;
 
+import org.apache.lucene.util.BytesRef;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -24,20 +26,27 @@ final class BKDUtil {
     // No instance
   }
 
-  /** result = a - b */
+  /** result = a - b, where a >= b */
   public static void subtract(int bytesPerDim, int dim, byte[] a, byte[] b, byte[] result) {
+    System.out.println("subtract a=" + bytesToInt(a, dim) + " b=" + bytesToInt(b, dim));
     int start = dim * bytesPerDim;
     int end = start + bytesPerDim;
-    int carry = 0;
+    System.out.println("  a=" + new BytesRef(a, start, bytesPerDim));
+    System.out.println("  b=" + new BytesRef(b, start, bytesPerDim));
+    int borrow = 0;
     for(int i=end-1;i>=start;i--) {
-      int diff = (a[i]&0xff) - (b[i]&0xff) - carry;
+      int diff = (a[i]&0xff) - (b[i]&0xff) - borrow;
       if (diff < 0) {
-        diff += 255;
-        carry = 1;
+        diff += 256;
+        borrow = 1;
+      } else {
+        borrow = 0;
       }
       result[i-start] = (byte) diff;
     }
-    assert carry == 0;
+    if (borrow != 0) {
+      throw new IllegalArgumentException("a < b?");
+    }
   }
   
   /** Returns positive int if a > b, negative int if a < b and 0 if a == b */

Modified: lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java?rev=1708913&r1=1708912&r2=1708913&view=diff
==============================================================================
--- lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java (original)
+++ lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java Fri Oct 16 08:32:53 2015
@@ -27,6 +27,8 @@ import java.util.Comparator;
 import org.apache.lucene.codecs.CodecUtil;
 import org.apache.lucene.store.ByteArrayDataInput;
 import org.apache.lucene.store.ByteArrayDataOutput;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.store.RAMOutputStream;
 import org.apache.lucene.util.ArrayUtil;
@@ -97,6 +99,9 @@ public final class BKDWriter {
   /** numDims * bytesPerDim */
   final int packedBytesLength;
 
+  final Directory tempDir;
+  final String tempFileNamePrefix;
+
   final byte[] scratchMax;
   final byte[] scratchDiff;
   final byte[] scratchPackedValue;
@@ -106,18 +111,20 @@ public final class BKDWriter {
   private OfflineSorter.ByteSequencesWriter offlinePointWriter;
   private HeapPointWriter heapPointWriter;
 
-  private Path tempInput;
+  private IndexOutput tempInput;
   private final int maxPointsInLeafNode;
   private final int maxPointsSortInHeap;
 
   private long pointCount;
 
-  public BKDWriter(int numDims, int bytesPerDim) throws IOException {
-    this(numDims, bytesPerDim, DEFAULT_MAX_POINTS_IN_LEAF_NODE, DEFAULT_MAX_MB_SORT_IN_HEAP);
+  public BKDWriter(Directory tempDir, String tempFileNamePrefix, int numDims, int bytesPerDim) throws IOException {
+    this(tempDir, tempFileNamePrefix, numDims, bytesPerDim, DEFAULT_MAX_POINTS_IN_LEAF_NODE, DEFAULT_MAX_MB_SORT_IN_HEAP);
   }
 
-  public BKDWriter(int numDims, int bytesPerDim, int maxPointsInLeafNode, float maxMBSortInHeap) throws IOException {
+  public BKDWriter(Directory tempDir, String tempFileNamePrefix, int numDims, int bytesPerDim, int maxPointsInLeafNode, float maxMBSortInHeap) throws IOException {
     verifyParams(numDims, maxPointsInLeafNode, maxMBSortInHeap);
+    this.tempDir = tempDir;
+    this.tempFileNamePrefix = tempFileNamePrefix;
     this.maxPointsInLeafNode = maxPointsInLeafNode;
     this.numDims = numDims;
     this.bytesPerDim = bytesPerDim;
@@ -168,7 +175,7 @@ public final class BKDWriter {
     System.out.println("W: switchToOffline");
 
     // For each .add we just append to this input file, then in .finish we sort this input and resursively build the tree:
-    tempInput = Files.createTempFile(OfflineSorter.getDefaultTempDir(), "in", "");
+    tempInput = tempDir.createTempOutput(tempFileNamePrefix, "bkd", IOContext.DEFAULT);
     offlinePointWriter = new OfflineSorter.ByteSequencesWriter(tempInput);
     PointReader reader = heapPointWriter.getReader(0);
     for(int i=0;i<pointCount;i++) {
@@ -215,7 +222,7 @@ public final class BKDWriter {
 
   /** Changes incoming {@link ByteSequencesWriter} file to to fixed-width-per-entry file, because we need to be able to slice
    *  as we recurse in {@link #build}. */
-  private PointWriter convertToFixedWidth(Path in) throws IOException {
+  private PointWriter convertToFixedWidth(String in) throws IOException {
     BytesRefBuilder scratch = new BytesRefBuilder();
     scratch.grow(bytesPerDoc);
     BytesRef bytes = scratch.get();
@@ -225,8 +232,9 @@ public final class BKDWriter {
     PointWriter sortedPointWriter = null;
     boolean success = false;
     byte[] packedValue = new byte[packedBytesLength];
+    // nocommit try-w-resources?
     try {
-      reader = new OfflineSorter.ByteSequencesReader(in);
+      reader = new OfflineSorter.ByteSequencesReader(tempDir.openInput(in, IOContext.READONCE));
       sortedPointWriter = getPointWriter(pointCount);
       for (long i=0;i<pointCount;i++) {
         boolean result = reader.read(scratch);
@@ -320,12 +328,29 @@ public final class BKDWriter {
   private PointWriter sort(int dim) throws IOException {
 
     if (heapPointWriter != null) {
+      System.out.println("sort in heap dim=" + dim);
+
+      HeapPointWriter sorted;
+
+      if (dim == 0) {
+        // First dim can re-use the current heap writer
+        sorted = heapPointWriter;
+      } else {
+        // Subsequent dims need a private copy
+        sorted = new HeapPointWriter((int) pointCount, (int) pointCount, packedBytesLength);
+        sorted.copyFrom(heapPointWriter);
+      }
 
-      sortHeapPointWriter(heapPointWriter, 0, (int) pointCount, dim);
+      sortHeapPointWriter(sorted, 0, (int) pointCount, dim);
 
       // nocommit shrink wrap?
-      heapPointWriter.close();
-      return heapPointWriter;
+      byte[] tmp = new byte[packedBytesLength];
+      for(int i=0;i<pointCount;i++) {
+        sorted.readPackedValue(i, tmp);
+        System.out.println("  docID=" + sorted.docIDs[i] + " value=" + BKDUtil.bytesToInt(tmp, dim));
+      }
+      sorted.close();
+      return sorted;
     } else {
 
       // Offline sort:
@@ -363,20 +388,21 @@ public final class BKDWriter {
         }
       };
 
-      Path sorted = Files.createTempFile(OfflineSorter.getDefaultTempDir(), "sorted", "");
       boolean success = false;
-      
+
+      OfflineSorter sorter = new OfflineSorter(tempDir, tempFileNamePrefix, cmp);
+      String sortedFileName = sorter.sort(tempInput.getName());
+
+      // nocommit try-w-resources
       try {
-        OfflineSorter sorter = new OfflineSorter(cmp);
-        sorter.sort(tempInput, sorted);
-        PointWriter writer = convertToFixedWidth(sorted);
+        PointWriter writer = convertToFixedWidth(sortedFileName);
         success = true;
         return writer;
       } finally {
         if (success) {
-          IOUtils.rm(sorted);
+          tempDir.deleteFile(sortedFileName);
         } else {
-          IOUtils.deleteFilesIgnoringExceptions(sorted);
+          IOUtils.deleteFilesIgnoringExceptions(tempDir, sortedFileName);
         }
       }
     }
@@ -429,8 +455,10 @@ public final class BKDWriter {
       sortedPointWriters[dim] = new PathSlice(sort(dim), 0, pointCount);
     }
 
-    // nocommit make sure this happens on exc:
-    IOUtils.rm(tempInput);
+    // nocommit make sure this happens on exc, use TrackingDirWrapper
+    if (tempInput != null) {
+      tempDir.deleteFile(tempInput.getName());
+    }
     heapPointWriter = null;
 
     byte[] minPacked = new byte[packedBytesLength];
@@ -496,29 +524,21 @@ public final class BKDWriter {
     assert ordBitSet.cardinality() == 0: "cardinality=" + ordBitSet.cardinality();
 
     // Read the split value: just open a reader, seek'd to the next value after leftCount, then read its value:
-    PointReader reader = source.writer.getReader(source.start + source.count - rightCount);
-    boolean success = false;
-    try {
+    try (PointReader reader = source.writer.getReader(source.start + source.count - rightCount)) {
       boolean result = reader.next();
       assert result;
 
       System.arraycopy(reader.packedValue(), splitDim*bytesPerDim, scratchMax, 0, bytesPerDim);
 
       ordBitSet.set(reader.ord());
+      System.out.println("  docID=" + reader.ord());
 
       // Start at 1 because we already did the first value above (so we could keep the split value):
       for(int i=1;i<rightCount;i++) {
         result = reader.next();
         assert result;
         ordBitSet.set(reader.ord());
-      }
-
-      success = true;
-    } finally {
-      if (success) {
-        IOUtils.close(reader);
-      } else {
-        IOUtils.closeWhileHandlingException(reader);
+        System.out.println("  docID=" + reader.ord());
       }
     }
 
@@ -530,7 +550,9 @@ public final class BKDWriter {
 
   /** Called only in assert */
   private boolean valueInBounds(byte[] packedValue, byte[] minPackedValue, byte[] maxPackedValue) {
+    System.out.println("  check");
     for(int dim=0;dim<numDims;dim++) {
+      System.out.println("    dim=" + dim + " value=" + BKDUtil.bytesToInt(packedValue, dim) + " vs min=" + BKDUtil.bytesToInt(minPackedValue, dim) + " max=" + BKDUtil.bytesToInt(maxPackedValue, dim));
       if (BKDUtil.compare(bytesPerDim, packedValue, dim, minPackedValue, dim) < 0) {
         return false;
       }
@@ -566,21 +588,21 @@ public final class BKDWriter {
                      byte[] splitPackedValues,
                      long[] leafBlockFPs) throws IOException {
 
-    int splitDim = split(minPackedValue, maxPackedValue);
-
     for(PathSlice slice : slices) {
       assert slice.count == slices[0].count;
     }
 
-    PathSlice source = slices[splitDim];
-
-    if (DEBUG) System.out.println("\nBUILD: nodeID=" + nodeID + " leafNodeOffset=" + leafNodeOffset + " splitDim=" + splitDim + "\n  count=" + source.count + "\n  source=" + source +
-                                  "\n  min=" + BKDUtil.bytesToInt(minPackedValue, 0) + " max=" + BKDUtil.bytesToInt(maxPackedValue, 0));
+    if (DEBUG) System.out.println("\nBUILD: nodeID=" + nodeID + " leafNodeOffset=" + leafNodeOffset + "\n  count=" + slices[0].count);
+    for(int dim=0;dim<numDims;dim++) {
+      System.out.println("  " + dim + ": source=" + slices[dim] + " min=" + BKDUtil.bytesToInt(minPackedValue, dim) + " max=" + BKDUtil.bytesToInt(maxPackedValue, dim));
+    }
 
     if (nodeID >= leafNodeOffset) {
       // Leaf node: write block
       if (DEBUG) System.out.println("  leaf");
 
+      PathSlice source = slices[0];
+
       // We ensured that maxPointsSortInHeap was >= maxPointsInLeafNode, so we better be in heap at this point:
       assert source.writer instanceof HeapPointWriter;
       HeapPointWriter heapSource = (HeapPointWriter) source.writer;
@@ -620,6 +642,12 @@ public final class BKDWriter {
     } else {
       // Inner node: partition/recurse
 
+      int splitDim = split(minPackedValue, maxPackedValue);
+
+      PathSlice source = slices[splitDim];
+
+      System.out.println("  splitDim=" + splitDim + " source=" + source + " right docs:");
+
       assert nodeID < splitPackedValues.length: "nodeID=" + nodeID + " splitValues.length=" + splitPackedValues.length;
 
       // How many points will be in the left tree:
@@ -627,6 +655,7 @@ public final class BKDWriter {
       long leftCount = source.count - rightCount;
 
       byte[] splitValue = markRightTree(rightCount, splitDim, source, ordBitSet);
+      System.out.println("  split value=" + BKDUtil.bytesToInt(splitValue, 0));
       int address = nodeID * (1+bytesPerDim);
       splitPackedValues[address] = (byte) splitDim;
       System.arraycopy(splitValue, 0, splitPackedValues, address + 1, bytesPerDim);
@@ -643,6 +672,7 @@ public final class BKDWriter {
       System.arraycopy(maxPackedValue, 0, maxSplitPackedValue, 0, packedBytesLength);
 
       for(int dim=0;dim<numDims;dim++) {
+
         if (dim == splitDim) {
           // No need to partition on this dim since it's a simple slice of the incoming already sorted slice.
           leftSlices[dim] = new PathSlice(source.writer, source.start, leftCount);
@@ -652,6 +682,8 @@ public final class BKDWriter {
           continue;
         }
 
+        System.out.println("  partition dim=" + dim);
+
         PointWriter leftPointWriter = null;
         PointWriter rightPointWriter = null;
         PointReader reader = null;
@@ -736,7 +768,7 @@ public final class BKDWriter {
       return new HeapPointWriter(size, size, packedBytesLength);
     } else {
       System.out.println("  offline");
-      return new OfflinePointWriter(count, packedBytesLength);
+      return new OfflinePointWriter(tempDir, tempFileNamePrefix, count, packedBytesLength);
     }
   }
 }

Modified: lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/HeapPointWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/HeapPointWriter.java?rev=1708913&r1=1708912&r2=1708913&view=diff
==============================================================================
--- lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/HeapPointWriter.java (original)
+++ lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/HeapPointWriter.java Fri Oct 16 08:32:53 2015
@@ -43,6 +43,18 @@ final class HeapPointWriter implements P
     valuesPerBlock = Math.max(1, 4096/packedBytesLength);
   }
 
+  public void copyFrom(HeapPointWriter other) {
+    if (docIDs.length < other.nextWrite) {
+      throw new IllegalStateException("docIDs.length=" + docIDs.length + " other.nextWrite=" + other.nextWrite);
+    }
+    System.arraycopy(other.docIDs, 0, docIDs, 0, other.nextWrite);
+    System.arraycopy(other.ords, 0, ords, 0, other.nextWrite);
+    for(byte[] block : other.blocks) {
+      blocks.add(block.clone());
+    }
+    nextWrite = other.nextWrite;
+  }
+
   void readPackedValue(int index, byte[] bytes) {
     assert bytes.length == packedBytesLength;
     int block = index / valuesPerBlock;

Modified: lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointReader.java?rev=1708913&r1=1708912&r2=1708913&view=diff
==============================================================================
--- lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointReader.java (original)
+++ lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointReader.java Fri Oct 16 08:32:53 2015
@@ -23,31 +23,25 @@ import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.InputStreamDataInput;
 import org.apache.lucene.util.RamUsageEstimator;
 
 final class OfflinePointReader implements PointReader {
-  final InputStreamDataInput in;
+  final IndexInput in;
   long countLeft;
   private final byte[] packedValue;
   private long ord;
   private int docID;
   final int bytesPerDoc;
 
-  OfflinePointReader(Path tempFile, int packedBytesLength, long start, long length) throws IOException {
+  OfflinePointReader(Directory tempDir, String tempFileName, int packedBytesLength, long start, long length) throws IOException {
     bytesPerDoc = packedBytesLength + RamUsageEstimator.NUM_BYTES_LONG + RamUsageEstimator.NUM_BYTES_INT;
+    in = tempDir.openInput(tempFileName, IOContext.READONCE);
     long seekFP = start * bytesPerDoc;
-    // nocommit cutover to Directory API
-    InputStream fis = Files.newInputStream(tempFile);
-    long skipped = 0;
-    while (skipped < seekFP) {
-      long inc = fis.skip(seekFP - skipped);
-      skipped += inc;
-      if (inc == 0) {
-        throw new RuntimeException("skip returned 0");
-      }
-    }
-    in = new InputStreamDataInput(new BufferedInputStream(fis));
+    in.seek(seekFP);
     this.countLeft = length;
     packedValue = new byte[packedBytesLength];
   }

Modified: lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java?rev=1708913&r1=1708912&r2=1708913&view=diff
==============================================================================
--- lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java (original)
+++ lucene/dev/branches/lucene6825/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java Fri Oct 16 08:32:53 2015
@@ -23,6 +23,9 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 
 import org.apache.lucene.store.ByteArrayDataOutput;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.store.OutputStreamDataOutput;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.OfflineSorter;
@@ -30,18 +33,17 @@ import org.apache.lucene.util.RamUsageEs
 
 final class OfflinePointWriter implements PointWriter {
 
-  final Path tempFile;
-  final OutputStreamDataOutput out;
+  final Directory tempDir;
+  final IndexOutput out;
   final long count;
   final int packedBytesLength;
   final int bytesPerDoc;
   private long countWritten;
   private boolean closed;
 
-  public OfflinePointWriter(long count, int packedBytesLength) throws IOException {
-    tempFile = Files.createTempFile(OfflineSorter.getDefaultTempDir(), "size" + count + ".", "");
-    // nocommit cutover to Directory API
-    out = new OutputStreamDataOutput(new BufferedOutputStream(Files.newOutputStream(tempFile)));
+  public OfflinePointWriter(Directory tempDir, String tempFileNamePrefix, long count, int packedBytesLength) throws IOException {
+    this.tempDir = tempDir;
+    out = tempDir.createTempOutput(tempFileNamePrefix, "bkd", IOContext.DEFAULT);
     this.packedBytesLength = packedBytesLength;
     bytesPerDoc = packedBytesLength + RamUsageEstimator.NUM_BYTES_LONG + RamUsageEstimator.NUM_BYTES_INT;
     this.count = count;
@@ -59,7 +61,7 @@ final class OfflinePointWriter implement
   @Override
   public PointReader getReader(long start) throws IOException {
     assert closed;
-    return new OfflinePointReader(tempFile, packedBytesLength, start, count-start);
+    return new OfflinePointReader(tempDir, out.getName(), packedBytesLength, start, count-start);
   }
 
   @Override
@@ -73,12 +75,12 @@ final class OfflinePointWriter implement
 
   @Override
   public void destroy() throws IOException {
-    IOUtils.rm(tempFile);
+    tempDir.deleteFile(out.getName());
   }
 
   @Override
   public String toString() {
-    return "OfflinePointWriter(count=" + count + " tempFile=" + tempFile + ")";
+    return "OfflinePointWriter(count=" + count + " tempFileName=" + out.getName() + ")";
   }
 }
 

Modified: lucene/dev/branches/lucene6825/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6825/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java?rev=1708913&r1=1708912&r2=1708913&view=diff
==============================================================================
--- lucene/dev/branches/lucene6825/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java (original)
+++ lucene/dev/branches/lucene6825/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java Fri Oct 16 08:32:53 2015
@@ -124,7 +124,7 @@ public class TestBKD extends LuceneTestC
 
   public void testBasicInts1D() throws Exception {
     try (Directory dir = newDirectory()) {
-      BKDWriter w = new BKDWriter(1, 4, 2, 1.0f);
+      BKDWriter w = new BKDWriter(dir, "tmp", 1, 4, 2, 1.0f);
       byte[] scratch = new byte[4];
       for(int docID=0;docID<100;docID++) {
         intToBytes(docID, scratch, 0);
@@ -192,7 +192,7 @@ public class TestBKD extends LuceneTestC
       int numDims = TestUtil.nextInt(random(), 1, 5);
       int maxPointsInLeafNode = TestUtil.nextInt(random(), 50, 100);
       float maxMB = (float) 0.1 + (3*random().nextFloat());
-      BKDWriter w = new BKDWriter(numDims, 4, maxPointsInLeafNode, maxMB);
+      BKDWriter w = new BKDWriter(dir, "tmp", numDims, 4, maxPointsInLeafNode, maxMB);
 
       int numDocs = atLeast(1000);
       if (VERBOSE) {
@@ -202,9 +202,11 @@ public class TestBKD extends LuceneTestC
       byte[] scratch = new byte[4*numDims];
       for(int docID=0;docID<numDocs;docID++) {
         int[] values = new int[numDims];
+        System.out.println("  docID=" + docID);
         for(int dim=0;dim<numDims;dim++) {
           values[dim] = random().nextInt();
           intToBytes(values[dim], scratch, dim);
+          System.out.println("    " + dim + " -> " + values[dim]);
         }
         docs[docID] = values;
         w.add(scratch, docID);
@@ -301,4 +303,6 @@ public class TestBKD extends LuceneTestC
       }
     }
   }
+
+  // nocommit multivalued test
 }