You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2018/06/06 11:03:27 UTC

[2/3] jena git commit: JENA-1552: Phased loader

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/main/LoaderPlans.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/main/LoaderPlans.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/main/LoaderPlans.java
new file mode 100644
index 0000000..a97693c
--- /dev/null
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/main/LoaderPlans.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2.loader.main;
+
+import org.apache.jena.tdb2.loader.basic.LoaderBasic;
+import org.apache.jena.tdb2.loader.sequential.LoaderSequential;
+
+/** 
+ * Some algorithms expressed as {@link LoaderPlan}s. 
+ */
+public class LoaderPlans {
+
+    /**
+     * Data phase: data to SPO and GSPO. <br/>
+     * Index phase: POS and OSP + GPOS and GOSP <br/>
+     * Index phase: SPOG, POSG and OSPG
+     * <p>
+     * on the principle that data is often triples or quads, but rarely a collection of
+     * both in bulk.
+     * </p><p>
+     * This is the default loader option for {@code tdb2.tdbloader}, {@code --loader=phased}. 
+     * </p> 
+     */
+    public static LoaderPlan loaderPlanPhased = new LoaderPlan(
+        InputStage.MULTI,
+        new String[]{ "SPO" },
+        new String[]{ "GSPO" },
+        new String[][]{ { "POS", "OSP" } },
+        new String[][]{ {"GPOS", "GOSP"}, {"SPOG", "POSG", "OSPG"} }
+        );
+    
+    /**
+     * Do everything at once.  Maximum parallel action - may swamp the machine and be slower than {@link #loaderPlanPhased}.
+     * <p>
+     * Data phase: data to SPO and all secondary indexes; and to GSPO and all secondary indexes. <br/>
+     * No other phases.
+     * <p>
+     * This is the loader option for {@code tdb2.tdbloader --loader=parallel}. 
+     */
+    public static LoaderPlan loaderPlanParallel = new LoaderPlan(
+        InputStage.MULTI,
+        new String[]{ "SPO", "POS", "OSP" },
+        new String[]{ "GSPO", "GPOS", "GOSP", "SPOG", "POSG", "OSPG" },
+        new String[][]{ },
+        new String[][]{ }
+        );
+    
+    /**
+     * A nearly sequential process, as a loader plan including single threaded first
+     * phase. Each index is calculated separately but on a separate thread.
+     * <p>
+     * It is similar in performance and characteristics of
+     * {@code tdb2.tdbloader --loader=sequential}, which is provided by
+     * {@link LoaderSequential}.
+     * 
+     * @see LoaderSequential
+     */
+    public static LoaderPlan loaderPlanMinimal = new LoaderPlan(
+        InputStage.PARSE_NODE_INDEX,
+        new String[]{ "SPO" },
+        new String[]{ "GSPO" },
+        new String[][]{ { "POS" } , { "OSP" } },
+        new String[][]{ { "GPOS" }, { "GOSP" }, { "SPOG" }, { "POSG" } , { "OSPG" } }
+        );
+    
+    /**
+     * A simple loader - do everything, at once, on the calling thread.
+     * {@link LoaderBasic} is a similar algorithm but with a wrapper transaction
+     * and not manipulating TDB2 via internal means. 
+     * <p> 
+     * It is similar in performance to {@code tdb2.tdbloader --loader=basic},
+     * which is provided by {@link LoaderBasic}.
+     * 
+     * @see LoaderBasic
+     */
+    public static LoaderPlan loaderPlanSimple = new LoaderPlan(
+        InputStage.PARSE_NODE_INDEX,
+        new String[]{ "SPO" , "POS" , "OSP" },
+        new String[]{ "GSPO" , "GPOS"  , "GOSP" , "SPOG" ,  "POSG" , "OSPG" }, 
+        new String[][]{},
+        new String[][]{}
+        );
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/main/PhasedOps.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/main/PhasedOps.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/main/PhasedOps.java
new file mode 100644
index 0000000..7bb0420
--- /dev/null
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/main/PhasedOps.java
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2.loader.main;
+
+import java.util.*;
+import java.util.function.Consumer;
+import java.util.function.IntFunction;
+import java.util.stream.Stream;
+
+import org.apache.jena.atlas.lib.tuple.Tuple;
+import org.apache.jena.tdb2.loader.BulkLoaderException;
+import org.apache.jena.tdb2.loader.base.MonitorOutput;
+import org.apache.jena.tdb2.loader.base.ProgressMonitor;
+import org.apache.jena.tdb2.loader.base.ProgressMonitorFactory;
+import org.apache.jena.tdb2.store.DatasetGraphTDB;
+import org.apache.jena.tdb2.store.NodeId;
+import org.apache.jena.tdb2.store.tupletable.TupleIndex;
+
+/**
+ * Library of operations used by {@link LoaderMain}.
+ */
+class PhasedOps {
+
+    static Map<String, TupleIndex> indexMap(DatasetGraphTDB dsgtdb) {
+        Map<String, TupleIndex> indexMap = new HashMap<>();
+        // All triple/quad indexes.
+        Arrays.stream(dsgtdb.getTripleTable().getNodeTupleTable().getTupleTable().getIndexes())
+              .forEach(idx->indexMap.put(idx.getName(), idx));
+        Arrays.stream(dsgtdb.getQuadTable().getNodeTupleTable().getTupleTable().getIndexes())
+              .forEach(idx->indexMap.put(idx.getName(), idx));
+        return indexMap;
+    }
+    
+    static TupleIndex[][] indexSetsFromNames(String[][] indexNames, Map<String, TupleIndex> indexMap) {
+        // Bad error message!
+        //return deepMap(indexNames, indexMap::get, TupleIndex[]::new, TupleIndex[][]::new);  
+        TupleIndex[][] z = Arrays.stream(indexNames)
+            .map(indexSetNames->indexSetFromNames(indexSetNames, indexMap))
+            .toArray(TupleIndex[][]::new);
+        return z;
+    }
+    
+    static TupleIndex[] indexSetFromNames(String[] indexNames, Map<String, TupleIndex> indexMap) {
+        return Arrays.stream(indexNames)
+            .map(name-> findInIndexMap(name, indexMap))
+            .toArray(TupleIndex[]::new);
+    }
+
+    static TupleIndex findInIndexMap(String name,Map<String, TupleIndex> indexMap) {
+        TupleIndex tIdx = indexMap.get(name);
+        if ( tIdx == null )
+            throw new IllegalArgumentException("No such index: "+name);
+        return tIdx;
+    }
+    
+    /** Check the loader plan makes sense. */ 
+    private static void checkLoaderPlan(LoaderPlan loaderPlan, Map<String, TupleIndex> indexMap) {
+        Consumer<String> checker3 = name -> {
+            if ( name == null ) throw new BulkLoaderException("Null index name");
+            if ( name.length() != 3 ) throw new BulkLoaderException("Bad length (expected 3): "+name);
+            if ( !indexMap.containsKey(name) ) throw new BulkLoaderException("No such index: "+name);
+        };
+        Consumer<String> checker4 = name -> {
+            if ( name == null ) throw new BulkLoaderException("Null index name");
+            if ( name.length() != 4 ) throw new BulkLoaderException("Bad length (expected 4): "+name);
+            if ( !indexMap.containsKey(name) ) throw new BulkLoaderException("No such index: "+name);
+        };
+        
+        // -- Checking for nulls and bad index names.
+        arrayApply1(loaderPlan.primaryLoad3(), checker3);
+        arrayApply1(loaderPlan.primaryLoad4(), checker4);
+        
+        arrayApply2(loaderPlan.secondaryIndex3(), checker3);
+        arrayApply2(loaderPlan.secondaryIndex4(), checker4);
+        
+        // -- Checking for duplicates
+        checkUnique("Primary triples",loaderPlan.primaryLoad3());
+        checkUnique("Primary quads", loaderPlan.primaryLoad4());
+        
+        String[] secondary3 = flatten(loaderPlan.secondaryIndex3(), String[]::new);
+        String[] secondary4 = flatten(loaderPlan.secondaryIndex4(), String[]::new);
+        
+        checkUnique("Secondary triples", secondary3);
+        checkUnique("Secondary quads", secondary4);
+    }
+
+    private static <X> void checkUnique(String errorMessage, X[] array) {
+        Set<X> set = new HashSet<>();
+        for ( X x : array ) {
+            if ( set.contains(x) )
+                throw new BulkLoaderException(errorMessage+" : Not unique: "+x);
+            set.add(x);
+        }
+    }
+
+    /** Indexes to a list of mappings suitable as a label  */
+    /*package*/ static String indexMappings(TupleIndex[] indexes) {
+        StringJoiner sj = new StringJoiner(", ");
+        Arrays.stream(indexes).map(x->x.getMappingStr()).forEach(str->sj.add(str));
+        return sj.toString();
+    }
+
+    // Hide java noise with specific function implementations of some operations. 
+    
+    private static <X> void arrayApply2(X[][] array, Consumer<X> action) {
+        if ( array == null )
+            return;
+        for ( X[] lines : array ) {
+            for ( X item : lines ) {
+                action.accept(item);
+            }
+        }
+    }
+    
+    private static <X> void arrayApply1(X[] array, Consumer<X> action) {
+        if ( array == null )
+            return;
+        for ( X item : array ) {
+            action.accept(item);
+        }
+    }
+
+    private static <X> X[] flatten(X[][] array, IntFunction<X[]> generator) {
+        return flatten(array).toArray(generator);
+    }
+    
+    private static <X> Stream<X> flatten(X[][] array) {
+        if ( array == null )
+            return null;
+        return Arrays.stream(array).flatMap(Arrays::stream);
+    }
+    
+    static class ReplayResult {
+        final long items;
+        final long elapsed;
+        ReplayResult(long items, long timeInMs) {
+            this.items = items;
+            this.elapsed = timeInMs;
+        }
+    }
+
+    /** Return (Number, Time in ms) */
+    
+    static ReplayResult replay(TupleIndex srcIdx, Destination<Tuple<NodeId>> dest, MonitorOutput output) {
+        ProgressMonitor monitor = 
+            ProgressMonitorFactory.progressMonitor("Index", output, LoaderMain.IndexTickPoint, LoaderMain.IndexSuperTick);
+        
+        List<Tuple<NodeId>> block = null;
+
+        int len = srcIdx.getTupleLength();
+        
+        monitor.start();
+        Iterator<Tuple<NodeId>> iter = srcIdx.all();
+        while (iter.hasNext()) {
+            if ( block == null )
+                block = new ArrayList<>(LoaderConst.ChunkSize);
+            Tuple<NodeId> row = iter.next();
+            block.add(row);
+            monitor.tick();
+            if ( block.size() == LoaderConst.ChunkSize ) {
+                dest.deliver(block);
+                block = null;
+            }
+        }
+        if ( block != null )
+            dest.deliver(block);
+        dest.deliver(Collections.emptyList());
+        monitor.finish();
+        //monitor.finishMessage("Tuples["+len+"]");
+        return new ReplayResult(monitor.getTicks(), monitor.getTime());
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/main/PrefixHandler.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/main/PrefixHandler.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/main/PrefixHandler.java
new file mode 100644
index 0000000..8bc0cd0
--- /dev/null
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/main/PrefixHandler.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2.loader.main;
+
+import java.util.function.BiConsumer;
+
+import org.apache.jena.dboe.transaction.txn.Transaction;
+import org.apache.jena.dboe.transaction.txn.TransactionCoordinator;
+import org.apache.jena.query.TxnType;
+import org.apache.jena.tdb2.loader.base.BulkStartFinish;
+import org.apache.jena.tdb2.loader.base.CoLib;
+import org.apache.jena.tdb2.loader.base.MonitorOutput;
+import org.apache.jena.tdb2.store.DatasetPrefixesTDB;
+import org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable; 
+
+/**
+ * Prefix handler. 
+ * <p>
+ * This class is not multithreaded - prefixes are usually few enough in number
+ * and so forking a thread so that work can be done in parallel is not beneficial.
+ */
+public class PrefixHandler implements BulkStartFinish {
+    
+    private Transaction transaction;
+    private TransactionCoordinator coordinator;
+    private DatasetPrefixesTDB prefixes;
+    private MonitorOutput output;
+    
+    public PrefixHandler(DatasetPrefixesTDB prefixes, MonitorOutput output) {
+        this.prefixes = prefixes;
+        this.output = output;
+    }
+    
+    // Inline, not a separate thread.
+    @Override
+    public void startBulk() {
+        TransactionCoordinator coordinator = CoLib.newCoordinator();
+        NodeTupleTable p = prefixes.getNodeTupleTable();
+        CoLib.add(coordinator, p.getNodeTable());
+        CoLib.add(coordinator, p.getTupleTable().getIndexes());
+        coordinator.start();
+        transaction = coordinator.begin(TxnType.WRITE);
+    }
+
+    @Override
+    public void finishBulk() {
+        transaction.commit();
+    }
+
+    public BiConsumer<String, String> handler() {
+        return (prefix, uriStr) -> 
+            prefixes.insertPrefix(DatasetPrefixesTDB.unnamedGraphURI, prefix, uriStr);
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/BulkProcesses.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/BulkProcesses.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/BulkProcesses.java
deleted file mode 100644
index 057fcef..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/BulkProcesses.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.tdb2.loader.parallel;
-
-import java.util.List;
-
-import org.apache.jena.ext.com.google.common.collect.Lists;
-
-public class BulkProcesses {
-    
-    public static void start(List<BulkStartFinish> list) {
-        list.forEach(x->x.startBulk());
-    }
-    
-    public static void finish(List<BulkStartFinish> list) {
-        Lists.reverse(list).forEach(x->x.finishBulk());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/BulkStartFinish.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/BulkStartFinish.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/BulkStartFinish.java
deleted file mode 100644
index 5453a89..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/BulkStartFinish.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.tdb2.loader.parallel;
-
-public interface BulkStartFinish {
-    public void startBulk();
-    public void finishBulk();
-    
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/CoLib.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/CoLib.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/CoLib.java
deleted file mode 100644
index ea790a7..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/CoLib.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.tdb2.loader.parallel;
-
-import org.apache.jena.dboe.base.file.Location;
-import org.apache.jena.dboe.transaction.txn.TransactionCoordinator;
-import org.apache.jena.dboe.transaction.txn.journal.Journal;
-import org.apache.jena.tdb2.loader.base.LoaderOps;
-import org.apache.jena.tdb2.store.nodetable.NodeTable;
-import org.apache.jena.tdb2.store.tupletable.TupleIndex;
-
-/** Per-thread TransactionCoordinator helpers. */
-/*package*/ public class CoLib {
-    
-    /*package*/ public static TransactionCoordinator newCoordinator() {
-        Journal journal = Journal.create(Location.mem());
-        return new TransactionCoordinator(journal);
-    }
-    
-    /*package*/ public static void add(TransactionCoordinator coordinator, NodeTable nodeTable) {
-        coordinator.add(LoaderOps.ntDataFile(nodeTable));
-        coordinator.add(LoaderOps.ntBPTree(nodeTable));
-    }
-    
-    /*package*/ public static void add(TransactionCoordinator coordinator, TupleIndex... indexes) {
-        for ( TupleIndex pIdx : indexes ) {
-            coordinator.add(LoaderOps.idxBTree(pIdx));
-        }
-    }
-
-    /*package*/ public static void start(TransactionCoordinator coordinator) {
-        coordinator.start();
-    }
-    
-    /*package*/ public static void finish(TransactionCoordinator coordinator) {
-        // Donot do this - it will shutdown the TrasnactionComponents as well.
-        //coordinator.shutdown();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataBatcher.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataBatcher.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataBatcher.java
deleted file mode 100644
index 0fbc20f..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataBatcher.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.tdb2.loader.parallel;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.function.BiConsumer;
-import java.util.function.Consumer;
-
-import org.apache.jena.graph.Triple;
-import org.apache.jena.riot.lang.StreamRDFCounting;
-import org.apache.jena.riot.system.StreamRDF;
-import org.apache.jena.sparql.core.Quad;
-import org.apache.jena.tdb2.loader.base.MonitorOutput;
-
-/**
- * A {@link StreamRDF} that groups triples and quads and dispatches them in batches. This
- * class is a {@link StreamRDF} and runs on the calling thread; it does not create any
- * threads.
- */   
-public class DataBatcher implements StreamRDFCounting, BulkStartFinish {
-    
-    private List<Triple> triples = null;
-    private List<Quad> quads = null;
-    private long countTriples;
-    private long countQuads;
-    private final MonitorOutput output;
-    private  BiConsumer<String, String> prefixHandler;
-    private Consumer<DataBlock> batchDestination;
-    
-    public DataBatcher(Consumer<DataBlock> batchDestination,
-                       BiConsumer<String, String> prefixHandler,
-                       MonitorOutput output) {
-        this(batchDestination, prefixHandler, LoaderParallel.DataTickPoint, LoaderParallel.DataSuperTick, output);
-    }
-    
-    public DataBatcher(Consumer<DataBlock> batchDestination,
-                       BiConsumer<String, String> prefixHandler, 
-                       int tickPoint, int superTick, MonitorOutput output) {
-        this.batchDestination = batchDestination;
-        this.output = output;
-        this.prefixHandler = prefixHandler;
-    }
-    
-    @Override
-    public void startBulk() {}
-
-    @Override
-    public void finishBulk() {
-        DataBlock lastData = null;
-        if ( ! isEmpty(triples) || ! isEmpty(quads) ) {
-            lastData = new DataBlock(triples, quads);
-            dispatch(lastData);
-            triples = null;
-            quads = null;
-        }
-        dispatch(DataBlock.END);
-    }
-    
-    private <X> boolean isEmpty(List<X> list) {
-        return list == null || list.isEmpty() ;
-    }
-    
-    @Override public void start() {}
-
-    @Override public void finish() {}
-
-    @Override public long count()           { return countTriples() + countQuads(); }
-
-    @Override public long countTriples()    { return countTriples; }
-
-    @Override public long countQuads()      { return countQuads; }
-    
-    @Override
-    public void triple(Triple triple) {
-        if ( triples == null )
-            triples = allocChunkTriples();
-        triples.add(triple);
-        countTriples++;
-        maybeDispatch();
-    }
-
-    @Override
-    public void quad(Quad quad) {
-        if ( quad.isTriple() || quad.isDefaultGraph() ) {
-            // Shame about the object creation.
-            triple(quad.asTriple());
-            return;
-        }
-        if ( quads == null )
-            quads = allocChunkQuads();
-        quads.add(quad);
-        countQuads++;
-        maybeDispatch();
-    }
-
-    private void maybeDispatch() {
-        long x = 0;
-        if ( triples != null )
-            x += triples.size();
-        if ( quads != null )
-            x += quads.size();
-        if ( x <= LoaderConst.ChunkSize )
-            return ;
-        
-        DataBlock block = new DataBlock(triples, quads) ;
-        // Dispatch.
-        dispatch(block);
-        triples = null;
-        quads = null;
-    }
-
-    private void dispatch(DataBlock datablock) {
-        batchDestination.accept(datablock);
-    }
-
-    
-//    private void maybeDispatch3() {
-//        if ( triples.size() >= LoaderConst.ChunkSize ) {
-//            dispatchTriples(triples);
-//            triples = null;
-//        }
-//    }
-//    
-//    private void maybeDispatch4() {
-//        if ( quads.size() >= LoaderConst.ChunkSize ) {
-//            dispatchQuads(quads);
-//            quads = null;
-//        }
-//    }
-//
-//    private void dispatchTriples(List<Triple> triples) {
-//        destTriples.deliver(triples);
-//    }
-//
-//    private void dispatchQuads(List<Quad> quads) {
-//        destQuads.deliver(quads);
-//    }
-
-    @Override
-    public void base(String base) {}
-
-    @Override
-    public void prefix(String prefix, String iri) {
-        if ( prefixHandler != null )
-            prefixHandler.accept(prefix, iri);
-    }
-
-    private List<Triple>  allocChunkTriples() {
-        return new ArrayList<>(LoaderConst.ChunkSize); 
-    } 
-
-    private List<Quad>  allocChunkQuads() {
-        return new ArrayList<>(LoaderConst.ChunkSize); 
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataBlock.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataBlock.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataBlock.java
deleted file mode 100644
index 2fb540c..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataBlock.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.tdb2.loader.parallel;
-
-import java.util.List;
-
-import org.apache.jena.graph.Triple;
-import org.apache.jena.sparql.core.Quad;
-
-/** Unit of output from the data batcher */ 
-public class DataBlock {
-    /** Unique end marker object */ 
-    static DataBlock END = new DataBlock(null, null);
-     
-    List<Triple> triples = null;
-    List<Quad> quads = null;
-    DataBlock( List<Triple> triples, List<Quad> quads) {
-        this.triples = triples;
-        this.quads = quads;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataToTuples.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataToTuples.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataToTuples.java
deleted file mode 100644
index 33f107d..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataToTuples.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.tdb2.loader.parallel;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-import java.util.function.Consumer;
-import java.util.function.Function;
-
-import org.apache.jena.atlas.lib.tuple.Tuple;
-import org.apache.jena.atlas.lib.tuple.TupleFactory;
-import org.apache.jena.dboe.transaction.txn.Transaction;
-import org.apache.jena.dboe.transaction.txn.TransactionCoordinator;
-import org.apache.jena.graph.Node;
-import org.apache.jena.graph.Triple;
-import org.apache.jena.query.TxnType;
-import org.apache.jena.sparql.core.DatasetPrefixStorage;
-import org.apache.jena.sparql.core.Quad;
-import org.apache.jena.tdb2.loader.BulkLoaderException;
-import org.apache.jena.tdb2.loader.base.MonitorOutput;
-import org.apache.jena.tdb2.store.DatasetGraphTDB;
-import org.apache.jena.tdb2.store.NodeId;
-import org.apache.jena.tdb2.store.nodetable.NodeTable;
-
-/** Batch processing of {@link DataBlock}s (triples or Quads) converting them to two output of
- * to blocks of {@code Tuple<NodeId>}.
- * <p>
- * This class runs one task thread.
- * <p>
- * Data is deliver into the process by calling the provided functions for {@code Destination<Tuple<NodeId>}.
- * <p>
- * Assumes triples and quads share a node table.
- */ 
- 
-public class DataToTuples implements BulkStartFinish {
-    private long countTriples;
-    private long countQuads;
-
-    private final Destination<Tuple<NodeId>> dest3;
-    private final Destination<Tuple<NodeId>> dest4;
-    private final DatasetGraphTDB dsgtdb;
-    private final NodeTable nodeTable;
-    private final DatasetPrefixStorage prefixes;
-
-    // Chunk accumulators.
-    private List<Tuple<NodeId>> quads = null;
-    private List<Tuple<NodeId>> triples = null;
-    private final MonitorOutput output;
-    private BlockingQueue<DataBlock> input;
-
-    public DataToTuples(DatasetGraphTDB dsgtdb, Destination<Tuple<NodeId>> tuples3, Destination<Tuple<NodeId>> tuples4, MonitorOutput output) {
-        this.dsgtdb = dsgtdb;
-        this.dest3 = tuples3;
-        this.dest4 = tuples4;
-        this.input = new ArrayBlockingQueue<>(LoaderConst.QueueSizeData);
-        this.nodeTable = dsgtdb.getQuadTable().getNodeTupleTable().getNodeTable();
-        this.prefixes = dsgtdb.getPrefixes();
-        this.output = output;
-        
-        NodeTable nodeTable2 = dsgtdb.getTripleTable().getNodeTupleTable().getNodeTable();
-        if ( nodeTable != nodeTable2 )
-            throw new BulkLoaderException("Different node tables");
-    }
-    
-    private TransactionCoordinator coordinator;
-    private Transaction transaction; 
-    
-    public Consumer<DataBlock> data() {
-        return this::index; 
-    }
-    
-    private void index(DataBlock dataBlock) {
-        try { input.put(dataBlock); }
-        catch (InterruptedException e) {
-            throw new BulkLoaderException("InterruptedException", e);
-        }
-    }
-    
-    @Override
-    public void startBulk() {
-        new Thread(()->action()).start();
-    }
-     
-    @Override
-    public void finishBulk() { }
-
-    // Triples.
-    private void action() {
-        coordinator = CoLib.newCoordinator();
-        CoLib.add(coordinator, nodeTable);
-        CoLib.start(coordinator);
-        transaction = coordinator.begin(TxnType.WRITE);
-
-        try {
-            for (;;) {
-                
-                DataBlock data = input.take();
-                if ( data == DataBlock.END )
-                    break;
-                if ( data.triples != null ) {
-                    List<Tuple<NodeId>> tuples = new ArrayList<>(data.triples.size());
-                    for ( Triple t : data.triples ) {
-                        countTriples++;
-                        accTuples(t, nodeTable, tuples);
-                    }
-                    dispatchTuples3(tuples);
-                }
-                if ( data.quads != null ) {
-                    List<Tuple<NodeId>> tuples = new ArrayList<>(data.quads.size());
-                    for ( Quad q : data.quads ) {
-                        countQuads++;
-                        accTuples(q, nodeTable, tuples);
-                    }
-                    dispatchTuples4(tuples);
-                }
-            }
-            dispatchTuples3(LoaderConst.END_TUPLES);
-            dispatchTuples4(LoaderConst.END_TUPLES);
-            transaction.commit();
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            transaction.abort();
-        }
-        transaction.end();
-        CoLib.finish(coordinator);
-    }
-
-    //@Override
-    public long getCountTriples()   { return countTriples; }
-    //@Override
-    public long getCountQuads()     { return countQuads; }
-
-    private void dispatchTuples3(List<Tuple<NodeId>> chunk) {
-        dest3.deliver(chunk);
-    }
-    
-    private void dispatchTuples4(List<Tuple<NodeId>> chunk) {
-        dest4.deliver(chunk);
-    }
-
-    private static void accTuples(Triple triple, NodeTable nodeTable, List<Tuple<NodeId>> acc) {
-        acc.add(nodes(nodeTable, triple));
-    }
-    
-    private static void accTuples(Quad quad, NodeTable nodeTable, List<Tuple<NodeId>> acc) {
-        acc.add(nodes(nodeTable, quad));
-    }
-    
-    // Recycle?
-    private List<Tuple<NodeId>> allocChunkTriples() {
-        return new ArrayList<>(LoaderConst.ChunkSize); 
-    } 
-
-    private List<Tuple<NodeId>> allocChunkQuads() {
-        return new ArrayList<>(LoaderConst.ChunkSize); 
-    }
-
-    private static Tuple<NodeId> nodes(NodeTable nt, Triple triple) {
-        NodeId s = idForNode(nt, triple.getSubject());
-        NodeId p = idForNode(nt, triple.getPredicate());
-        NodeId o = idForNode(nt, triple.getObject());
-        return TupleFactory.tuple(s,p,o);
-    }
-    
-    private Function<List<Quad>, List<Tuple<NodeId>>> quadsToNodeIds(NodeTable nodeTable) {
-        return (List<Quad> quads) -> {
-            List<Tuple<NodeId>> x = new ArrayList<>(quads.size()); 
-            for(Quad quad: quads) {
-                x.add(nodes(nodeTable, quad));
-            }
-            return x;
-        };
-    }
-
-    private static Tuple<NodeId> nodes(NodeTable nt, Quad quad) {
-        NodeId g = idForNode(nt, quad.getGraph());
-        NodeId s = idForNode(nt, quad.getSubject());
-        NodeId p = idForNode(nt, quad.getPredicate());
-        NodeId o = idForNode(nt, quad.getObject());
-        return TupleFactory.tuple(g,s,p,o);
-    }
-    
-    private static final NodeId idForNode(NodeTable nodeTable, Node node) {
-        return nodeTable.getAllocateNodeId(node);
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataToTuplesInline.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataToTuplesInline.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataToTuplesInline.java
deleted file mode 100644
index bca7158..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/DataToTuplesInline.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.tdb2.loader.parallel;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.jena.atlas.lib.tuple.Tuple;
-import org.apache.jena.atlas.lib.tuple.TupleFactory;
-import org.apache.jena.dboe.transaction.txn.Transaction;
-import org.apache.jena.dboe.transaction.txn.TransactionCoordinator;
-import org.apache.jena.graph.Node;
-import org.apache.jena.graph.Triple;
-import org.apache.jena.query.TxnType;
-import org.apache.jena.riot.lang.StreamRDFCounting;
-import org.apache.jena.riot.system.StreamRDF;
-import org.apache.jena.sparql.core.DatasetPrefixStorage;
-import org.apache.jena.sparql.core.Quad;
-import org.apache.jena.tdb2.loader.BulkLoaderException;
-import org.apache.jena.tdb2.loader.base.MonitorOutput;
-import org.apache.jena.tdb2.store.DatasetGraphTDB;
-import org.apache.jena.tdb2.store.DatasetPrefixesTDB;
-import org.apache.jena.tdb2.store.NodeId;
-import org.apache.jena.tdb2.store.nodetable.NodeTable;
-import org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable;
-
-/** Triple to chunks of Tuples.  
- *  Same thread version.
- *  This is a {@link StreamRDF}.
- *  Also loads prefixes.
- */ 
-public class DataToTuplesInline implements StreamRDFCounting, BulkStartFinish {
-    public static final int DataTickPoint   = 100_000;
-    public static final int DataSuperTick   = 10;
-    
-    private final Destination<Tuple<NodeId>> dest3;
-    private final Destination<Tuple<NodeId>> dest4;
-    private final DatasetGraphTDB dsgtdb;
-    private final NodeTable nodeTable;
-    private final DatasetPrefixStorage prefixes;
-
-    private final MonitorOutput output;
-    // Chunk accumulators.
-    private long countTriples = 0;
-    private long countQuads = 0;
-    private List<Tuple<NodeId>> quads = null;
-    private List<Tuple<NodeId>> triples = null;
-    // Prefix handler.
-    public DataToTuplesInline(DatasetGraphTDB dsgtdb,
-                              Destination<Tuple<NodeId>> dest3,
-                              Destination<Tuple<NodeId>> dest4, 
-                              MonitorOutput output) {
-        this.dsgtdb = dsgtdb;
-        this.dest3 = dest3;
-        this.dest4 = dest4;
-        this.output = output;
-        this.nodeTable = dsgtdb.getTripleTable().getNodeTupleTable().getNodeTable();
-        this.prefixes = dsgtdb.getPrefixes();
-        NodeTable nodeTable2 = dsgtdb.getQuadTable().getNodeTupleTable().getNodeTable();
-        if ( nodeTable != nodeTable2 )
-            throw new BulkLoaderException("Different node tables");
-    }
-    
-    // StreamRDF
-    private TransactionCoordinator coordinator;
-    private Transaction transaction; 
-    @Override
-    public void startBulk() {
-        coordinator = CoLib.newCoordinator();
-        CoLib.add(coordinator, nodeTable);
-        
-        // Prefixes
-        NodeTupleTable p = ((DatasetPrefixesTDB)prefixes).getNodeTupleTable();
-        CoLib.add(coordinator, p.getNodeTable());
-        CoLib.add(coordinator, p.getTupleTable().getIndexes());
-        CoLib.start(coordinator);
-        transaction = coordinator.begin(TxnType.WRITE);
-    }
-
-    @Override
-    public void finishBulk() {
-        if ( triples != null && ! triples.isEmpty() ) {
-            dispatchTriples(triples);
-            triples = null;
-        }
-        dispatchTriples(LoaderConst.END_TUPLES);
-        transaction.commit();
-        transaction.end();
-        CoLib.finish(coordinator);
-    }
-
-    @Override public void start() {}
-
-    @Override public void finish() {}
-
-    @Override public long count()           { return countTriples() + countQuads(); }
-
-    @Override public long countTriples()    { return countTriples; }
-
-    @Override public long countQuads()      { return countQuads; }
-
-    @Override
-    public void triple(Triple triple) {
-        countTriples++;
-        if ( triples == null )
-            triples = allocChunkTriples();
-        accTuples(triple, nodeTable, triples);
-        if ( triples.size() >= LoaderConst.ChunkSize ) {
-            dispatchTriples(triples);
-            triples = null;
-        }
-    }
-
-    @Override
-    public void quad(Quad quad) {
-        if ( quad.isTriple() || quad.isDefaultGraph() ) {
-            triple(quad.asTriple());
-            return;
-        }
-        countQuads++;
-        if ( quads == null )
-            quads = allocChunkQuads();
-        accTuples(quad, nodeTable, quads);
-        if ( quads.size() >= LoaderConst.ChunkSize ) {
-            dispatchQuads(quads);
-            quads = null;
-        }
-    }
-    
-    private void dispatchQuads(List<Tuple<NodeId>> chunk) {
-        dest4.deliver(chunk);
-    }
-
-    private void dispatchTriples(List<Tuple<NodeId>> chunk) {
-        dest3.deliver(chunk);
-    }
-    
-    @Override
-    public void base(String base) {}
-
-    @Override
-    public void prefix(String prefix, String iri) {
-        // Clean constant handling.
-        prefixes.insertPrefix("", prefix, iri);
-    }
-
-    private static void accTuples(Triple triple, NodeTable nodeTable, List<Tuple<NodeId>> acc) {
-        acc.add(nodes(nodeTable, triple));
-    }
-    
-    private static void accTuples(Quad quad, NodeTable nodeTable, List<Tuple<NodeId>> acc) {
-        acc.add(nodes(nodeTable, quad));
-    }
-    
-    // Recycle?
-    private List<Tuple<NodeId>> allocChunkTriples() {
-        return new ArrayList<>(LoaderConst.ChunkSize); 
-    } 
-
-    private List<Tuple<NodeId>> allocChunkQuads() {
-        return new ArrayList<>(LoaderConst.ChunkSize); 
-    }
-
-    private static Tuple<NodeId> nodes(NodeTable nt, Triple triple) {
-        NodeId s = idForNode(nt, triple.getSubject());
-        NodeId p = idForNode(nt, triple.getPredicate());
-        NodeId o = idForNode(nt, triple.getObject());
-        return TupleFactory.tuple(s,p,o);
-    }
-    
-   private static Tuple<NodeId> nodes(NodeTable nt, Quad quad) {
-        NodeId g = idForNode(nt, quad.getGraph());
-        NodeId s = idForNode(nt, quad.getSubject());
-        NodeId p = idForNode(nt, quad.getPredicate());
-        NodeId o = idForNode(nt, quad.getObject());
-        return TupleFactory.tuple(g,s,p,o);
-    }
-    
-    private static final NodeId idForNode(NodeTable nodeTable, Node node) {
-        return nodeTable.getAllocateNodeId(node);
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/Destination.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/Destination.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/Destination.java
deleted file mode 100644
index 00c4d76..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/Destination.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.tdb2.loader.parallel;
-
-import java.util.List;
-
-/** Unit of delivery to a processing stage. */
-@FunctionalInterface
-public interface Destination<X> {
-    void deliver(List<X> block); 
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/Indexer.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/Indexer.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/Indexer.java
deleted file mode 100644
index d591514..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/Indexer.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.tdb2.loader.parallel;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.Semaphore;
-
-import org.apache.jena.atlas.lib.ArrayUtils;
-import org.apache.jena.atlas.lib.Timer;
-import org.apache.jena.atlas.lib.tuple.Tuple;
-import org.apache.jena.dboe.transaction.txn.Transaction;
-import org.apache.jena.dboe.transaction.txn.TransactionCoordinator;
-import org.apache.jena.query.TxnType;
-import org.apache.jena.tdb2.loader.base.MonitorOutput;
-import org.apache.jena.tdb2.store.NodeId;
-import org.apache.jena.tdb2.store.tupletable.TupleIndex;
-
-/**
- * Build index(es).
- * Provides a function {@link #index()} that should be called from another thread
- * to deliver chunks of tuples ({@code  List<Tuple<NodeId>>}).
- * Each chunk should be the same Tuyple length and this must correspond to the length of the {@link TupleIndex}s being loaded. 
- * <p>
- * This class creates one thread per {@link TupleIndex}.  
- */
-public class Indexer implements BulkStartFinish {
-
-    private BlockingQueue<List<Tuple<NodeId>>>[] pipesTripleIndexers;
-    private final int N;
-    private final MonitorOutput output;
-    private TupleIndex[] indexes;
-    private final Semaphore termination = new Semaphore(0);
-    
-    @SuppressWarnings("unchecked")
-    public Indexer(MonitorOutput output, TupleIndex... idxTriples) {
-        pipesTripleIndexers = ArrayUtils.alloc(BlockingQueue.class, idxTriples.length);
-        this.N = idxTriples.length;
-        this.indexes = Arrays.copyOf(idxTriples, N); 
-        this.output = output; 
-            
-        for ( int i = 0 ; i < N ; i++ ) {
-            pipesTripleIndexers[i] = new ArrayBlockingQueue<List<Tuple<NodeId>>>(LoaderConst.QueueSizeTuples);
-        }
-    }
-    
-    private static long acquire(Semaphore semaphore, int numPermits) {
-        return Timer.time(()->{
-            try { semaphore.acquire(numPermits); }
-            catch (InterruptedException e) { e.printStackTrace(); }
-        });
-    }
-    
-    /** Return a function that delivers multiple {@code List<Tuple<NodeId>>>} to this indexer */
-    public Destination<Tuple<NodeId>> index() {
-        return this::index; 
-    }
-    
-    private void index(List<Tuple<NodeId>> chunk) {
-        for ( int i = 0 ; i < N ; i++ ) {
-            try {
-                pipesTripleIndexers[i].put(chunk);
-            }
-            catch (InterruptedException e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
-    /** Start the threads that will do the indexing */ 
-    @Override
-    public void startBulk() {
-        for ( int i = 0 ; i < N ; i++ ) {
-            TupleIndex idx = indexes[i];
-            BlockingQueue<List<Tuple<NodeId>>> pipe = pipesTripleIndexers[i];
-            new Thread(()->stageIndex(pipe, idx)).start();
-        }
-    }
-    
-    /** Wait for all the indexing threads to complete. */ 
-    @Override
-    public void finishBulk() {
-        //output.print("Wait for %d indexers", N);
-        acquire(termination, N);
-    }
-    
-    private void stageIndex(BlockingQueue<List<Tuple<NodeId>>> pipe, TupleIndex idx) {
-        TransactionCoordinator coordinator = CoLib.newCoordinator();
-        CoLib.add(coordinator, idx);
-        CoLib.start(coordinator);
-        Transaction transaction = coordinator.begin(TxnType.WRITE);
-        boolean workHasBeenDone; 
-        try {
-            Destination<Tuple<NodeId>> loader = loadTuples(idx);
-            for (;;) {
-                List<Tuple<NodeId>> tuples = pipe.take();
-                if ( tuples.isEmpty() )
-                    break;
-                loader.deliver(tuples);
-            }
-            workHasBeenDone = ! idx.isEmpty();
-            transaction.commit();
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            transaction.abort();
-            workHasBeenDone = false;
-        }
-        CoLib.finish(coordinator);
-        if ( workHasBeenDone )
-            output.print("Finish - index %s", idx.getName());
-        termination.release();
-    }
-    
-    private static Destination<Tuple<NodeId>> loadTuples(TupleIndex index) {
-        return (List<Tuple<NodeId>> tuples) -> {
-            for(Tuple<NodeId> tuple : tuples)
-                index.add(tuple);
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/LoaderConst.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/LoaderConst.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/LoaderConst.java
deleted file mode 100644
index 665a329..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/LoaderConst.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.tdb2.loader.parallel;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.jena.atlas.lib.tuple.Tuple;
-import org.apache.jena.tdb2.store.NodeId;
-
-public class LoaderConst {
-
-    /** Chunk size for the triple->tuples output pipe */  
-    public final static int ChunkSize = 100_000 ;
-
-    /** Queue size for chunks of tuples Tuples */
-    public final static int QueueSizeTuples = 10;
-
-    //public final static int pipeSize = 10;
-    
-    /* package */ static final List<Tuple<NodeId>> END_TUPLES      = Collections.emptyList();
-
-    /*package*/ static final int QueueSizeData = 10;
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/LoaderParallel.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/LoaderParallel.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/LoaderParallel.java
deleted file mode 100644
index ae2696e..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/LoaderParallel.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.tdb2.loader.parallel;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.function.Consumer;
-
-import org.apache.jena.atlas.lib.tuple.Tuple;
-import org.apache.jena.graph.Node;
-import org.apache.jena.riot.system.StreamRDF;
-import org.apache.jena.sparql.core.DatasetGraph;
-import org.apache.jena.tdb2.loader.DataLoader;
-import org.apache.jena.tdb2.loader.base.LoaderBase;
-import org.apache.jena.tdb2.loader.base.LoaderOps;
-import org.apache.jena.tdb2.loader.base.MonitorOutput;
-import org.apache.jena.tdb2.store.DatasetGraphTDB;
-import org.apache.jena.tdb2.store.DatasetPrefixesTDB;
-import org.apache.jena.tdb2.store.NodeId;
-import org.apache.jena.tdb2.sys.TDBInternal;
-
-/**
- * The parallel Loader.
- * <p>
- * The process is:
- * <blockquote>
- * {@code DataBatcher -> DataToTuples -> Indexer}
- * </blockquote>
- * <p>
- * {@link DataBatcher} produces {@link DataBlock}s - grouping of triples and quads and sends them to a handler {@code Consumer<DataBlock>}. 
- * This is wired up to be the feed for {@code DataToTuples}. 
- * <p>
- * {@link DataToTuples} processes {@link DataBlock}s to create 2 outputs blocks of {@code Tuple<NodeId>}, one output for triples, one for quads,
- * and sends these to {@code Indexer}s for triples and quads. 
- * <p>
- * {@link Indexer} processes blocks of {@code Tuple<NodeId>} (of the same tuple length) and writes them to a number of indexes. 
- * Each index being written is a separate thread. 
- */
-public class LoaderParallel extends LoaderBase implements DataLoader {
-    public static final int DataTickPoint   = 500_000;
-    public static final int DataSuperTick   = 10;
-//    public static final int IndexTickPoint  = 1_000_000;
-//    public static final int IndexSuperTick  = 10;
-    
-    private final DatasetGraphTDB dsgtdb;
-    private PrefixHandler prefixHandler;
-    private StreamRDF stream;
-    private DataBatcher dataBatcher;
-    private DataToTuples dtt;
-    private Indexer indexer3;
-    private Indexer indexer4;
-    private List<BulkStartFinish> process = new ArrayList<>();
-    
-    public LoaderParallel(DatasetGraph dsg, MonitorOutput output) {
-        this(dsg, null, output);
-    }
-    
-    public LoaderParallel(DatasetGraph dsg, Node graphName, MonitorOutput output) {
-        super(dsg, graphName, output);
-        dsgtdb = TDBInternal.getDatasetGraphTDB(dsg);
-        
-        DatasetPrefixesTDB dps = (DatasetPrefixesTDB)dsgtdb.getPrefixes();
-        prefixHandler = new PrefixHandler(dps, output);
-        process.add(prefixHandler);
-        
-        // Contains a splitter of Tuples -> Tuples per index.
-        indexer3 = new Indexer(output, dsgtdb.getTripleTable().getNodeTupleTable().getTupleTable().getIndexes());
-        indexer4 = new Indexer(output, dsgtdb.getQuadTable().getNodeTupleTable().getTupleTable().getIndexes());
-
-        process.add(indexer4);
-        process.add(indexer3);
-        
-        Destination<Tuple<NodeId>> functionIndexer3 = indexer3.index();
-        Destination<Tuple<NodeId>> functionIndexer4 = indexer4.index();
-        
-        // Multi-thread input stage (2 threads).
-        dtt = new DataToTuples(dsgtdb, functionIndexer3, functionIndexer4, output);
-        Consumer<DataBlock> dest = dtt.data();
-        dataBatcher = new DataBatcher(dest, prefixHandler.handler(), output);
-        StreamRDF baseInput = dataBatcher;
-        process.add(dtt);
-        process.add(dataBatcher);
-        
-        // One thread input stage
-//      DataToTuplesInline dttInline = new DataToTuplesInline(dsgtdb, functionIndexer3, functionIndexer4, output);
-//      StreamRDF baseInput = dttInline;
-//       process.add(dttInline);
-        
-        stream = LoaderOps.toNamedGraph(baseInput, graphName);
-    }
-    
-    @Override
-    public StreamRDF stream() {
-        return stream;
-    }
-    
-    @Override
-    public boolean bulkUseTransaction() {
-        // Manipulate the transactions directly by component. 
-        return false;
-    }
-
-    @Override
-    public void startBulk() {
-        // Lock everyone else out while we multithread.
-        dsgtdb.getTxnSystem().getTxnMgr().startExclusiveMode();
-        super.startBulk();
-        BulkProcesses.start(process);
-    }
-
-    @Override
-    public void finishBulk() {
-        if ( output != null )
-            output.print("Waiting for background tasks to complete");
-        BulkProcesses.finish(process);
-        super.finishBulk();
-        dsgtdb.getTxnSystem().getTxnMgr().finishExclusiveMode();
-    }
-    
-    @Override
-    public void finishException(Exception ex) {
-        try { 
-            dsgtdb.getTxnSystem().getTxnMgr().finishExclusiveMode();
-        } catch (Exception ex2) {
-            ex.addSuppressed(ex2);
-        }
-    }
-    
-    @Override
-    public long countTriples() {
-        return dataBatcher.countTriples();
-    }
-
-    @Override
-    public long countQuads() {
-        return dataBatcher.countQuads();
-    }
-
-    @Override
-    protected void loadOne(String filename) {
-        LoaderOps.inputFile(stream, filename, output, DataTickPoint, DataSuperTick);
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/PrefixHandler.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/PrefixHandler.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/PrefixHandler.java
deleted file mode 100644
index 77c0d5e..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/parallel/PrefixHandler.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.tdb2.loader.parallel;
-
-import java.util.function.BiConsumer;
-
-import org.apache.jena.dboe.transaction.txn.Transaction;
-import org.apache.jena.dboe.transaction.txn.TransactionCoordinator;
-import org.apache.jena.query.TxnType;
-import org.apache.jena.tdb2.loader.base.MonitorOutput;
-import org.apache.jena.tdb2.store.DatasetPrefixesTDB;
-import org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable; 
-
-/**
- * Prefix handler. 
- * <p>
- * This class is not multithreaded - prefixes are usually few enough in number
- * and so forking a thread so that work can be done in parallel is not beneficial.
- */
-public class PrefixHandler implements BulkStartFinish {
-    
-    private Transaction transaction;
-    private TransactionCoordinator coordinator;
-    private DatasetPrefixesTDB prefixes;
-    private MonitorOutput output;
-    
-    public PrefixHandler(DatasetPrefixesTDB prefixes, MonitorOutput output) {
-        this.prefixes = prefixes;
-        this.output = output;
-    }
-    
-    // Inline, not a separate thread.
-    @Override
-    public void startBulk() {
-        TransactionCoordinator coordinator = CoLib.newCoordinator();
-        NodeTupleTable p = prefixes.getNodeTupleTable();
-        CoLib.add(coordinator, p.getNodeTable());
-        CoLib.add(coordinator, p.getTupleTable().getIndexes());
-        coordinator.start();
-        transaction = coordinator.begin(TxnType.WRITE);
-    }
-
-    @Override
-    public void finishBulk() {
-        transaction.commit();
-    }
-
-    public BiConsumer<String, String> handler() {
-        return (prefix, uriStr) -> 
-            prefixes.insertPrefix(DatasetPrefixesTDB.unnamedGraphURI, prefix, uriStr);
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/BuilderSecondaryIndexes.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/BuilderSecondaryIndexes.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/BuilderSecondaryIndexes.java
index 1c87df0..b1bec81 100644
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/BuilderSecondaryIndexes.java
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/BuilderSecondaryIndexes.java
@@ -18,14 +18,38 @@
 
 package org.apache.jena.tdb2.loader.sequential;
 
+import org.apache.jena.atlas.lib.Timer;
+import org.apache.jena.tdb2.loader.base.LoaderOps;
 import org.apache.jena.tdb2.loader.base.MonitorOutput;
+import org.apache.jena.tdb2.loader.base.ProgressMonitor;
+import org.apache.jena.tdb2.loader.base.ProgressMonitorOutput;
 import org.apache.jena.tdb2.store.tupletable.TupleIndex;
 
 /**
  * This interface is the mechanism for building indexes given that at leasts one index
  * already exists (the "primary", which normally is SPO or GSPO).
  */
-public interface BuilderSecondaryIndexes
+public class BuilderSecondaryIndexes
 {
-    public void createSecondaryIndexes(MonitorOutput output, TupleIndex primaryIndex, TupleIndex[] secondaryIndexes) ;
+    public static void createSecondaryIndexes(MonitorOutput output, TupleIndex primaryIndex, TupleIndex[] secondaryIndexes)
+    {
+        Timer timer = new Timer() ;
+        timer.startTimer() ;
+        boolean printTiming = true;
+        for ( TupleIndex index : secondaryIndexes ) {
+            if ( index != null ) {
+                ProgressMonitor monitor = ProgressMonitorOutput.create(output, index.getName(), 
+                                                                       LoaderSequential.IndexTickPoint,
+                                                                       LoaderSequential.IndexSuperTick);
+                monitor.startMessage();
+                monitor.start();
+
+                long time1 = timer.readTimer() ;
+                LoaderOps.copyIndex(primaryIndex.all(), new TupleIndex[]{index}, monitor) ;
+                long time2 = timer.readTimer() ;
+                monitor.finish();
+                monitor.finishMessage(index.getName()+" indexing: ");
+            }  
+        }   
+    }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/BuilderSecondaryIndexesSequential.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/BuilderSecondaryIndexesSequential.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/BuilderSecondaryIndexesSequential.java
deleted file mode 100644
index 5293fe2..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/BuilderSecondaryIndexesSequential.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.tdb2.loader.sequential;
-
-import org.apache.jena.atlas.lib.Timer ;
-import org.apache.jena.tdb2.loader.base.LoaderOps;
-import org.apache.jena.tdb2.loader.base.MonitorOutput;
-import org.apache.jena.tdb2.loader.base.ProgressMonitor;
-import org.apache.jena.tdb2.loader.base.ProgressMonitorOutput;
-import org.apache.jena.tdb2.store.tupletable.TupleIndex ;
-
-public class BuilderSecondaryIndexesSequential implements BuilderSecondaryIndexes
-{
-    public BuilderSecondaryIndexesSequential() {} 
-    
-    // Create each secondary indexes, doing one at a time.
-    @Override
-    public void createSecondaryIndexes(MonitorOutput output, TupleIndex primaryIndex, TupleIndex[] secondaryIndexes)
-    {
-        Timer timer = new Timer() ;
-        timer.startTimer() ;
-        boolean printTiming = true;
-        for ( TupleIndex index : secondaryIndexes ) {
-            if ( index != null ) {
-                ProgressMonitor monitor = ProgressMonitorOutput.create(output, index.getName(), 
-                                                                   LoaderSequential.IndexTickPoint,
-                                                                   LoaderSequential.IndexSuperTick);
-                monitor.startMessage();
-                monitor.start();
-
-                long time1 = timer.readTimer() ;
-                LoaderOps.copyIndex(primaryIndex.all(), new TupleIndex[]{index}, monitor) ;
-                long time2 = timer.readTimer() ;
-                monitor.finish();
-                monitor.finishMessage(index.getName()+" indexing: ");
-//                if ( printTiming )
-//                    output.print("Time for %s indexing: %.2fs", index.getName(), (time2-time1)/1000.0) ;
-            }  
-        }   
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/LoaderNodeTupleTable.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/LoaderNodeTupleTable.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/LoaderNodeTupleTable.java
index b15d77f..032cb46 100644
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/LoaderNodeTupleTable.java
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/loader/sequential/LoaderNodeTupleTable.java
@@ -28,7 +28,8 @@ import org.apache.jena.tdb2.store.tupletable.TupleIndex;
 
 /** 
  * Load into one NodeTupleTable (triples, quads, other).
- * 
+ * <br/>
+ * This is the TDB1 tdbloader algorithm ported to TDB2. 
  */
 
 public class LoaderNodeTupleTable implements Closeable, Sync
@@ -74,7 +75,7 @@ public class LoaderNodeTupleTable implements Closeable, Sync
         if ( count > 0 ) {
             if ( dropAndRebuildIndexes )
                 // Now do secondary indexes.
-                createSecondaryIndexes();
+                BuilderSecondaryIndexes.createSecondaryIndexes(output, primaryIndex, secondaryIndexes);
         }
         attachSecondaryIndexes();
     }
@@ -113,22 +114,8 @@ public class LoaderNodeTupleTable implements Closeable, Sync
         nodeTupleTable.addRow(nodes);
     }
 
-//    public void loadIndexStart()
-//    {
-//        if ( count > 0 )
-//            // Do index phase only if any items seen.
-//            monitor.startIndexPhase();
-//        // Always do this - it reattaches the secondary indexes.
-//        loadSecondaryIndexes();
-//    }
-//
-//    public void loadIndexFinish()
-//    {
-//        if ( count > 0 )
-//            monitor.finishIndexPhase();
-//    }
-    
     public void sync(boolean force) {}
+    
     @Override
     public void sync() {}
     
@@ -151,10 +138,9 @@ public class LoaderNodeTupleTable implements Closeable, Sync
             nodeTupleTable.getTupleTable().setTupleIndex(i, null);
     }
     
-    private void createSecondaryIndexes() {        
-        BuilderSecondaryIndexes builder = new BuilderSecondaryIndexesSequential();
-        builder.createSecondaryIndexes(output, primaryIndex, secondaryIndexes);
-    }
+//    private void createSecondaryIndexes() {        
+//        BuilderSecondaryIndexes.createSecondaryIndexes(output, primaryIndex, secondaryIndexes);
+//    }
     
     private void attachSecondaryIndexes() {
         for ( int i = 1; i < numIndexes; i++ )

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/loader/AbstractTestLoader.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/loader/AbstractTestLoader.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/loader/AbstractTestLoader.java
new file mode 100644
index 0000000..0462158
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/loader/AbstractTestLoader.java
@@ -0,0 +1,226 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2.loader ;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.function.BiFunction;
+
+import org.apache.jena.atlas.iterator.Iter;
+import org.apache.jena.atlas.logging.LogCtl;
+import org.apache.jena.graph.Graph;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.graph.Triple;
+import org.apache.jena.query.ARQ;
+import org.apache.jena.riot.RDFDataMgr;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.core.Quad;
+import org.apache.jena.sparql.util.IsoMatcher;
+import org.apache.jena.sys.JenaSystem;
+import org.apache.jena.system.Txn;
+import org.apache.jena.tdb2.DatabaseMgr;
+import org.apache.jena.tdb2.TDB2;
+import org.apache.jena.tdb2.loader.base.LoaderOps;
+import org.apache.jena.tdb2.loader.base.MonitorOutput;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public abstract class AbstractTestLoader {
+    static { JenaSystem.init(); }
+    
+    static MonitorOutput output = LoaderOps.nullOutput();
+    private String name;
+    private BiFunction<DatasetGraph, Node, DataLoader> maker;
+    
+    protected AbstractTestLoader(String name, BiFunction<DatasetGraph, Node, DataLoader> maker) {
+        this.name = name;
+        this.maker = maker;
+    }
+    
+    /** Load the contents of files or remote web data into a dataset. */
+    static void load(DatasetGraph dataset, BiFunction<DatasetGraph, Node, DataLoader> maker, String ... dataURLs) {
+        load(dataset, null, maker, dataURLs);
+    }
+    
+    static void load(DatasetGraph dataset, Node graphName, BiFunction<DatasetGraph, Node, DataLoader> maker, String ... dataURLs) {
+        DataLoader loader = maker.apply(dataset, graphName);
+        loader.startBulk();
+        try {
+            loader.load(dataURLs);
+            loader.finishBulk();
+        }
+        catch (RuntimeException ex) {
+            loader.finishException(ex);
+            throw ex;
+        }
+    }
+    
+    private static String DIR = "testing/Loader/";
+    private static final Node g  = NodeFactory.createURI("g") ;
+    private static final Node s  = NodeFactory.createURI("s") ;
+    private static final Node p  = NodeFactory.createURI("p") ;
+    private static final Node o  = NodeFactory.createURI("o") ;
+    private static final Node o1 = NodeFactory.createURI("o1") ;
+    private static final Node o2 = NodeFactory.createURI("o2") ;
+    
+    private static final Node gn  = NodeFactory.createURI("http://example/g") ;
+
+    @BeforeClass
+    static public void beforeClass() {
+        LogCtl.disable(ARQ.logExecName) ;
+        //LogCtl.disable(TDB2.logLoaderName) ;
+    }
+
+    @AfterClass
+    static public void afterClass() {
+        LogCtl.enable(ARQ.logExecName) ;
+        LogCtl.enable(TDB2.logLoaderName) ;
+    }
+
+    static DatasetGraph fresh() {
+        return DatabaseMgr.createDatasetGraph() ;
+    }
+
+    @Test
+    public void load_dataset_01() {
+        DatasetGraph dsg = fresh() ;
+        load(dsg, maker, DIR + "data-1.nq") ;
+        Txn.executeRead(dsg, ()->{
+            assertTrue(dsg.getDefaultGraph().isEmpty()) ;
+            assertEquals(1, dsg.getGraph(g).size()) ;
+        });
+    }
+
+    @Test
+    public void load_dataset_02() {
+        DatasetGraph dsg = fresh() ;
+        load(dsg, maker , DIR + "data-1.nq", DIR + "data-2.nt") ;
+        Txn.executeRead(dsg, ()->{
+            assertEquals(1, dsg.getGraph(g).size()) ;
+            assertEquals(2, dsg.getDefaultGraph().size());
+        });
+    }
+
+    @Test
+    public void load_dataset_03() {
+        DatasetGraph dsg = fresh();
+        DataLoader loader = maker.apply(dsg, null);
+        loader.startBulk();
+        RDFDataMgr.parse(loader.stream(), DIR + "data-1.nq");
+        loader.finishBulk();
+        Txn.executeRead(dsg, ()->{
+            assertTrue(dsg.getDefaultGraph().isEmpty()) ;
+            assertEquals(1, dsg.getGraph(g).size()) ;
+        });
+    }
+
+    @Test
+    public void load_dataset_04() {
+        DatasetGraph dsg = fresh() ;
+        load(dsg, maker, DIR + "data-3.trig") ;
+        Txn.executeRead(dsg, ()->{
+            String uri = dsg.getDefaultGraph().getPrefixMapping().getNsPrefixURI("") ;
+            assertEquals("http://example/", uri) ;
+        });
+    }
+    
+    @Test public void isomorphic_1() {
+        DatasetGraph dsg = fresh() ;
+        load(dsg, maker , DIR + "data-1.nq", DIR + "data-2.nt") ;
+        Txn.executeRead(dsg, ()->{
+            assertEquals(1, dsg.getGraph(g).size()) ;
+            assertEquals(2, dsg.getDefaultGraph().size());
+        });
+
+        DatasetGraph dsg1 = RDFDataMgr.loadDatasetGraph(DIR + "data-1.nq");
+        RDFDataMgr.read(dsg1, DIR + "data-2.nt");
+        Txn.executeRead(dsg, ()->{
+            boolean b = IsoMatcher.isomorphic(dsg1, dsg);
+            assertTrue("Not isomorphic", b);
+        });
+    }
+
+    @Test
+    public void load_dataset_indexes() {
+        DatasetGraph dsg = fresh() ;
+        load(dsg, maker, DIR + "data-1.nq", DIR + "data-2.nt") ;
+        Txn.executeRead(dsg, ()->{
+            assertEquals(2, dsg.getDefaultGraph().size()) ;
+            assertEquals(1, dsg.getGraph(g).size()) ;
+            
+            {
+                // Check indexes.
+                Graph g1 = dsg.getDefaultGraph();
+                List<Triple> x = Iter.toList(g1.find(null, null, null)) ;
+                assertEquals(2, x.size()) ;
+                x = Iter.toList(g1.find(s, null, null)) ;
+                assertEquals(2, x.size()) ;
+                x = Iter.toList(g1.find(null, p, null)) ;
+                assertEquals(2, x.size()) ;
+                x = Iter.toList(g1.find(null, null, o1)) ;
+                assertEquals(1, x.size()) ;
+            }
+
+            {
+                Graph g2 = dsg.getGraph(g);
+                List<Triple> x = Iter.toList(g2.find(null, null, null));
+                assertEquals(1, x.size());
+                x = Iter.toList(g2.find(s, null, null));
+                assertEquals(1, x.size());
+                x = Iter.toList(g2.find(null, p, null));
+                assertEquals(1, x.size());
+                x = Iter.toList(g2.find(null, null, o));
+                assertEquals(1, x.size());
+            }
+            
+            {
+                List<Quad> z = Iter.toList(dsg.find(null, null, null, null)) ;
+                assertEquals(3, z.size()) ;
+                z = Iter.toList(dsg.find(Quad.defaultGraphIRI, null, null, null)) ;
+                assertEquals(2, z.size()) ;
+                z = Iter.toList(dsg.find(g, null, null, null)) ;
+                assertEquals(1, z.size()) ;
+                z = Iter.toList(dsg.find(null, s, null, null)) ;
+                assertEquals(3, z.size()) ;
+                z = Iter.toList(dsg.find(null, null, p, null)) ;
+                assertEquals(3, z.size()) ;
+                z = Iter.toList(dsg.find(g, null, p, null)) ;
+                assertEquals(1, z.size()) ;
+                z = Iter.toList(dsg.find(null, null, null, o)) ;
+                assertEquals(1, z.size()) ;
+            }
+        });
+    }
+    
+    @Test
+    public void load_graph_1() {
+        DatasetGraph dsg = fresh() ;
+        load(dsg, gn, maker, DIR + "data-2.nt") ;
+        Txn.executeRead(dsg, ()->{
+            assertEquals(0, dsg.getDefaultGraph().size());
+            assertEquals(2, dsg.getGraph(gn).size());
+        });
+    }
+    
+    // Try to load quads.
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/2934c550/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/loader/TS_Loader.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/loader/TS_Loader.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/loader/TS_Loader.java
index 8621cd4..842544e 100644
--- a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/loader/TS_Loader.java
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/loader/TS_Loader.java
@@ -23,7 +23,8 @@ import org.junit.runners.Suite;
 
 @RunWith(Suite.class)
 @Suite.SuiteClasses( {
-    TestLoader.class
+    TestLoaderStd.class ,
+    TestLoaderMain.class
 })
 
 public class TS_Loader {}