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 2017/09/28 11:09:00 UTC
[44/50] [abbrv] jena git commit: JENA-1396: Merge //github/afs/mantis
as subdirectory jena-db/
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexTestLib.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexTestLib.java
index 0000000,0000000..f4dd9a8
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexTestLib.java
@@@ -1,0 -1,0 +1,218 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.index.test ;
++
++import static java.lang.String.format ;
++import static org.apache.jena.atlas.lib.ListUtils.asList ;
++import static org.apache.jena.atlas.lib.ListUtils.unique ;
++import static org.apache.jena.atlas.test.Gen.rand ;
++import static org.apache.jena.atlas.test.Gen.strings ;
++import static org.junit.Assert.assertEquals ;
++import static org.junit.Assert.assertNotNull ;
++import static org.junit.Assert.fail ;
++import static org.seaborne.dboe.test.RecordLib.intToRecord ;
++import static org.seaborne.dboe.test.RecordLib.r ;
++import static org.seaborne.dboe.test.RecordLib.toIntList ;
++
++import java.util.* ;
++
++import org.apache.jena.atlas.lib.RandomLib ;
++import org.apache.jena.ext.com.google.common.primitives.Ints;
++import org.junit.Assert ;
++import org.seaborne.dboe.base.record.Record ;
++import org.seaborne.dboe.index.Index ;
++import org.seaborne.dboe.index.RangeIndex ;
++import org.seaborne.dboe.test.RecordLib ;
++
++public class IndexTestLib {
++
++ // ---------- Utilities
++
++ // public static RangeIndex buildRangeIndex(RangeIndexMaker maker, int[]
++ // keys)
++ // {
++ // RangeIndex index = maker.make() ;
++ // IndexTestLib.add(index, keys) ;
++ // return index ;
++ // }
++
++ public static Index buildIndex(IndexMaker maker, int[] keys) {
++ Index index = maker.makeIndex() ;
++ IndexTestLib.add(index, keys) ;
++ return index ;
++ }
++
++ private static Random random = RandomLib.qrandom ;
++
++ public static void testIteration(RangeIndex index, int[] keys, int numIterations) {
++ // Shared across test-lets
++ SortedSet<Integer> x = new TreeSet<>() ;
++ for ( int v : keys )
++ x.add(v) ;
++
++ for ( int i = 0 ; i < numIterations ; i++ ) {
++ int lo = random.nextInt(keys.length) ;
++ int hi = random.nextInt(keys.length) ;
++ if ( lo > hi ) {
++ int t = lo ;
++ lo = hi ;
++ hi = t ;
++ }
++ // Does not consider nulls for min, max)
++ // That is assumed to be part of functional testing.
++ // Tweak lo and hi
++ if ( lo != 0 && random.nextFloat() < 0.5 )
++ lo-- ; // Negatives confuse the int/record code.
++ if ( random.nextFloat() < 0.5 )
++ hi++ ;
++
++ List<Integer> slice = r(index.iterator(r(lo), r(hi))) ;
++ List<Integer> expected = new ArrayList<>(keys.length) ;
++ for ( Integer ii : x.subSet(lo, hi) )
++ expected.add(ii) ;
++ if ( ! expected.equals(slice) )
++ assertEquals(format("(%d,%d)", lo, hi), expected, slice) ;
++ }
++ }
++
++ /* One random test : print the keys if there was a problem */
++
++ public static void randTest(Index index, int maxValue, int numKeys) {
++ randTest(index, maxValue, numKeys, true) ;
++ }
++ public static void randTest(Index index, int maxValue, int numKeys, boolean includeIteratorCheck) {
++ if ( numKeys >= 5000 )
++ System.err.printf("Warning: too many keys\n") ;
++
++ int[] keys1 = rand(numKeys, 0, maxValue) ;
++ int[] keys2 = permute2(keys1) ;
++ //int[] keys2 = permute(keys1, 4 * numKeys) ;
++ //System.err.printf("int[] keys1 = {%s} ;\n", strings(keys1)) ;
++ //System.err.printf("int[] keys2 = {%s}; \n", strings(keys2)) ;
++ try {
++ testInsert(index, keys1) ;
++ if ( true ) {
++ // Checking tests.
++ testIndexContents(index, keys2) ;
++ // Test iteration - quite expensive.
++ if ( includeIteratorCheck && index instanceof RangeIndex )
++ testIteration((RangeIndex)index, keys1, 10) ;
++ }
++ testDelete(index, keys2) ;
++ }
++ catch (AssertionError | RuntimeException ex) {
++ System.err.printf("Index : %s\n", index.getClass().getName()) ;
++ System.err.printf("int[] keys1 = {%s} ;\n", strings(keys1)) ;
++ System.err.printf("int[] keys2 = {%s}; \n", strings(keys2)) ;
++ throw ex ;
++ }
++ }
++
++ /** Pull items out of the list in a random order */
++ private static int[] permute2(int[] x) {
++ int[] ints = Arrays.copyOf(x, x.length);
++ List<Integer> list = Ints.asList(ints);
++ Collections.shuffle(list, random);
++ return ints;
++ }
++
++ private static Random randInit()
++ {
++ // Cheap random numbers, well seeded.
++ int seed = random.nextInt() ;
++ return new Random(seed) ;
++ }
++
++ // ---- Test utils
++
++ public static void testInsert(Index index, int[] keys) {
++ IndexTestLib.add(index, keys) ;
++ testIndexContents(index, keys) ;
++ }
++
++ public static Index testInsert(IndexMaker maker, int[] keys) {
++ Index index = maker.makeIndex() ;
++ testInsert(index, keys) ;
++ return index ;
++ }
++
++ public static void testInsertDelete(Index index, int[] buildKeys, int[] deleteKeys) {
++ testInsert(index, buildKeys) ;
++ testDelete(index, deleteKeys) ;
++ }
++
++ public static void testDelete(Index index, int[] vals) {
++ long size1 = index.size() ;
++
++ int count = 0 ;
++ count = delete(index, vals) ;
++
++ List<Record> x = intToRecord(vals, RecordLib.TestRecordLength) ;
++ for ( Record r : x )
++ Assert.assertFalse(index.contains(r)) ;
++ long size2 = index.size() ;
++
++ assertEquals(size1 - count, size2) ;
++ }
++
++ public static int delete(Index index, int... vals) {
++ int count = 0 ;
++ for ( int v : vals ) {
++ boolean b = index.delete(r(v)) ;
++ if ( b )
++ count++ ;
++ }
++ return count ;
++ }
++
++ public static void add(Index index, int... vals) {
++ // System.out.println("Add: "+Arrays.toString(vals)) ;
++ List<Record> x = intToRecord(vals, RecordLib.TestRecordLength) ;
++ for ( Record r : x ) {
++ // System.out.println(" Add: "+r) ;
++ index.insert(r) ;
++ }
++ }
++
++ public static void testIndexContents(Index index, int... records) {
++ List<Integer> x = toIntList(index.iterator()) ;
++
++ // Make a unique list of expected records. Remove duplicates
++ List<Integer> y = unique(asList(records)) ;
++
++ assertEquals("Expected records size and tree size different", y.size(), index.size()) ;
++ assertEquals("Expected records size and iteration over all keys are of different sizes", y.size(), x.size()) ;
++
++ if ( index instanceof RangeIndex ) {
++ // Check sorted order
++ for ( int i = 0 ; i < x.size() - 2 ; i++ ) {
++ if ( x.get(i) > x.get(i + 1) ) {
++ fail("check failed: " + strings(records)) ;
++ return ;
++ }
++ }
++ }
++
++ // Check each expected record is in the tree
++ for ( int k : y ) {
++ Record rec = intToRecord(k) ;
++ Record r2 = index.find(rec) ;
++ assertNotNull(r2) ;
++ }
++ }
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index-test/src/main/java/org/seaborne/dboe/index/test/RangeIndexMaker.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-index-test/src/main/java/org/seaborne/dboe/index/test/RangeIndexMaker.java
index 0000000,0000000..10c7b00
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index-test/src/main/java/org/seaborne/dboe/index/test/RangeIndexMaker.java
@@@ -1,0 -1,0 +1,27 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.index.test;
++
++import org.seaborne.dboe.index.RangeIndex ;
++
++public interface RangeIndexMaker extends IndexMaker
++{
++ RangeIndex makeRangeIndex() ;
++ @Override
++ String getLabel() ;
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index-test/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --cc jena-db/dboe-index-test/src/test/resources/log4j.properties
index 0000000,0000000..d6b299a
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index-test/src/test/resources/log4j.properties
@@@ -1,0 -1,0 +1,6 @@@
++log4j.rootLogger=INFO, stdlog
++
++log4j.appender.stdlog=org.apache.log4j.ConsoleAppender
++## log4j.appender.stdlog.target=System.err
++log4j.appender.stdlog.layout=org.apache.log4j.PatternLayout
++log4j.appender.stdlog.layout.ConversionPattern=%d{HH:mm:ss} %-5p %-20c{1} :: %m%n
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index/pom.xml
----------------------------------------------------------------------
diff --cc jena-db/dboe-index/pom.xml
index 0000000,0000000..28943de
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index/pom.xml
@@@ -1,0 -1,0 +1,42 @@@
++<?xml version="1.0" encoding="utf-8"?>
++<!--
++ Licensed 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.
++
++ See the NOTICE file distributed with this work for additional
++ information regarding copyright ownership.
++-->
++
++<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
++ <modelVersion>4.0.0</modelVersion>
++
++ <artifactId>dboe-index</artifactId>
++ <packaging>jar</packaging>
++ <name>Mantis (${project.artifactId})</name>
++
++ <parent>
++ <groupId>org.seaborne.mantis</groupId>
++ <artifactId>mantis</artifactId>
++ <version>0.3.1-SNAPSHOT</version>
++ </parent>
++
++ <dependencies>
++
++ <dependency>
++ <groupId>org.seaborne.mantis</groupId>
++ <artifactId>dboe-base</artifactId>
++ <version>0.3.1-SNAPSHOT</version>
++ </dependency>
++
++ </dependencies>
++
++</project>
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/Index.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/Index.java
index 0000000,0000000..ddf4800
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/Index.java
@@@ -1,0 -1,0 +1,91 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.index;
++
++import java.util.Iterator ;
++import java.util.stream.Stream ;
++
++import org.apache.jena.atlas.lib.Closeable ;
++import org.apache.jena.atlas.lib.Sync ;
++import org.seaborne.dboe.base.record.Record ;
++import org.seaborne.dboe.base.record.RecordFactory ;
++
++public interface Index extends Iterable<Record>, Sync, Closeable
++{
++ /** Find one record - and return the record actually in the index (may have a value part) */
++ public Record find(Record record) ;
++
++ /** Return whether the index contains the record or not. */
++ public boolean contains(Record record) ;
++
++ /** Insert a record - return true if an insertion was actually needed */
++ public boolean insert(Record record) ;
++
++ /** Delete a record - Return true if a record was actually removed */
++ public boolean delete(Record record) ;
++
++// public default void bulkInsert(Collection<Record> inserts) {
++// for ( Record r : inserts )
++// insert(r) ;
++// }
++//
++// public default void bulkDelete(Collection<Record> inserts) {
++// for ( Record r : inserts )
++// delete(r) ;
++// }
++
++ /** Bulk changes as given by a stream of changes.
++ * This is operations consumes the stream.
++ * @param changes
++ */
++ public default void bulkChanges(Stream<IndexChange> changes) {
++ changes.forEach(chg -> {
++ switch (chg.action) {
++ case ADD :
++ insert(chg.record) ;
++ break ;
++ case DELETE :
++ delete(chg.record) ;
++ break ;
++ }
++ }) ;
++ }
++
++ /** Iterate over the whole index */
++ @Override
++ public Iterator<Record> iterator() ;
++
++ /** Get the Record factory associated with this index */
++ public RecordFactory getRecordFactory() ;
++
++ /** Close the index - can not be used again through this object */
++ @Override
++ public void close() ;
++
++ /** Answer whether the index is empty or not. May return false for unknown or meaningless */
++ public boolean isEmpty() ;
++
++ /** Clear the index */
++ public void clear() ;
++
++ /** Perform checks on this index */
++ public void check() ;
++
++ /** Return size if known else return -1 : does not count the peristent storage */
++ public long size() ;
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexChange.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexChange.java
index 0000000,0000000..b296ae8
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexChange.java
@@@ -1,0 -1,0 +1,40 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.index;
++
++import java.util.Objects ;
++
++import org.seaborne.dboe.base.record.Record ;
++
++import org.apache.jena.sparql.core.DatasetChanges ;
++
++/** Temporary class to refine what to put into Jena itself.
++ * @see DatasetChanges
++ */
++public class IndexChange {
++ enum Action { ADD, DELETE }
++ final Action action ;
++ final Record record ;
++ public IndexChange(Action action, Record record) {
++ Objects.requireNonNull(action, "Action can not be null") ;
++ Objects.requireNonNull(record, "Record can not be null") ;
++ this.action = action ;
++ this.record = record ;
++ }
++}
++
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexConst.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexConst.java
index 0000000,0000000..08797f4
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexConst.java
@@@ -1,0 -1,0 +1,52 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.index;
++
++import org.seaborne.dboe.base.block.FileMode ;
++import org.seaborne.dboe.sys.SystemIndex ;
++
++public class IndexConst {
++
++ private static IndexParams stdParams = new IndexParamsStd() ;
++ public static IndexParams getDftParams() { return stdParams ; }
++
++ private static class IndexParamsStd implements IndexParams {
++
++ @Override
++ public FileMode getFileMode() {
++ return SystemIndex.fileMode() ;
++ }
++
++ @Override
++ public Integer getBlockSize() {
++ return SystemIndex.BlockSize ;
++ }
++
++ @Override
++ public Integer getBlockReadCacheSize() {
++ return SystemIndex.BlockReadCacheSize ;
++ }
++
++ @Override
++ public Integer getBlockWriteCacheSize() {
++ return SystemIndex.BlockWriteCacheSize ;
++ }
++
++ }
++}
++
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexLogger.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexLogger.java
index 0000000,0000000..ab2acf9
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexLogger.java
@@@ -1,0 -1,0 +1,64 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.index;
++
++import java.util.Iterator ;
++
++import org.seaborne.dboe.base.record.Record ;
++import org.slf4j.Logger ;
++
++public final class IndexLogger extends IndexWrapper
++{
++ private final Logger log ;
++
++ public IndexLogger(RangeIndex rIdx, Logger log)
++ {
++ super(rIdx) ;
++ this.log = log ;
++ }
++
++ @Override
++ public boolean insert(Record record)
++ {
++ log.info("Add: {}", record) ;
++ return super.insert(record) ;
++ }
++
++ @Override
++ public boolean delete(Record record)
++ {
++ log.info("Delete: {}", record) ;
++ return super.delete(record) ;
++ }
++
++ @Override
++ public Record find(Record record)
++ {
++ log.info("Find: {}", record) ;
++ Record r2 = super.find(record) ;
++ log.info("Find: "+record+" ==> "+r2) ;
++ return r2 ;
++ }
++
++ @Override
++ public Iterator<Record> iterator()
++ {
++ log.info("iterator()") ;
++ return super.iterator() ;
++ }
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexMap.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexMap.java
index 0000000,0000000..b176a84
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexMap.java
@@@ -1,0 -1,0 +1,171 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.index;
++
++import java.util.Arrays ;
++import java.util.HashMap ;
++import java.util.Iterator ;
++import java.util.Map ;
++
++import org.apache.jena.atlas.lib.Bytes ;
++import org.seaborne.dboe.base.record.Record ;
++import org.seaborne.dboe.base.record.RecordFactory ;
++
++/** A simple implementation of {@link Index} for testing */
++public class IndexMap implements Index
++{
++ private final Map<ByteArray, ByteArray> index = new HashMap<>() ;
++ private final RecordFactory recordFactory ;
++
++ public IndexMap(RecordFactory recordFactory)
++ {
++ this.recordFactory = recordFactory ;
++ }
++
++ @Override
++ public Record find(Record record)
++ {
++ ByteArray k = wrap(record.getKey()) ;
++ ByteArray v = index.get(k) ;
++ if ( v == null )
++ return null ;
++ return record(k, v) ;
++ }
++
++ @Override
++ public boolean contains(Record record)
++ {
++ Record r = find(record) ;
++ if ( r == null )
++ return false ;
++ if ( ! recordFactory.hasValue() )
++ return true ;
++ return Bytes.compare(record.getValue(), r.getValue()) == 0 ;
++ }
++
++ @Override
++ public boolean insert(Record record)
++ {
++ Record r = find(record) ;
++ if ( r != null && r.equals(record) )
++ return false ;
++ index.put(wrap(record.getKey()), wrap(record.getValue())) ;
++ return true ;
++ }
++
++ @Override
++ public boolean delete(Record record)
++ {
++ ByteArray x = index.remove(wrap(record.getKey())) ;
++ if ( x == null )
++ return false ;
++ return true ;
++ }
++
++ @Override
++ public Iterator<Record> iterator()
++ {
++ return new Iterator<Record>() {
++
++ Iterator<Map.Entry<ByteArray, ByteArray>> iter = index.entrySet().iterator() ;
++
++ @Override
++ public boolean hasNext()
++ {
++ return iter.hasNext() ;
++ }
++
++ @Override
++ public Record next()
++ {
++ Map.Entry<ByteArray, ByteArray> e = iter.next() ;
++ return record(e.getKey(), e.getValue()) ;
++ }
++
++ @Override
++ public void remove()
++ { throw new UnsupportedOperationException() ;}
++ } ;
++
++ }
++
++ @Override
++ public RecordFactory getRecordFactory()
++ {
++ return recordFactory ;
++ }
++
++ @Override
++ public boolean isEmpty()
++ {
++ return index.isEmpty() ;
++ }
++
++ @Override
++ public void clear()
++ {
++ index.clear() ;
++ }
++
++ @Override
++ public void check()
++ {}
++
++ @Override
++ public long size()
++ {
++ return index.size() ;
++ }
++
++ @Override
++ public void sync()
++ {}
++
++ @Override
++ public void close()
++ {}
++
++ private static ByteArray wrap(byte[] b) { return new ByteArray(b) ; }
++ private Record record(ByteArray k, ByteArray v) { return recordFactory.create(k.bytes, v.bytes) ; }
++
++ private static class ByteArray
++ {
++ byte[] bytes ;
++ ByteArray(byte[] bytes) { this.bytes = bytes ; }
++
++ @Override
++ public int hashCode()
++ {
++ final int prime = 31 ;
++ int result = 1 ;
++ result = prime * result + Arrays.hashCode(bytes) ;
++ return result ;
++ }
++ @Override
++ public boolean equals(Object obj)
++ {
++ if (this == obj) return true ;
++ if (obj == null) return false ;
++ if (getClass() != obj.getClass()) return false ;
++ ByteArray other = (ByteArray)obj ;
++ if (!Arrays.equals(bytes, other.bytes)) return false ;
++ return true ;
++ }
++ }
++
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexParams.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexParams.java
index 0000000,0000000..f3f25c9
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexParams.java
@@@ -1,0 -1,0 +1,37 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.index;
++
++import org.seaborne.dboe.base.block.BlockParams ;
++import org.seaborne.dboe.base.block.FileMode ;
++
++public interface IndexParams extends BlockParams {
++ /** File Mode */
++ @Override public FileMode getFileMode() ;
++
++ /** Block size - this is only configurable when the on-disk are created.
++ * After that, the same value as at creation must be used each time.
++ */
++ @Override public Integer getBlockSize() ;
++
++ /** Block read cache size (mmap'ed files do not have a block cache)*/
++ @Override public Integer getBlockReadCacheSize() ;
++
++ /** Block write cache size (mmap'ed files do not have a block cache)*/
++ @Override public Integer getBlockWriteCacheSize() ;
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexWrapper.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexWrapper.java
index 0000000,0000000..95de7f2
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/IndexWrapper.java
@@@ -1,0 -1,0 +1,91 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.index ;
++
++import java.util.Iterator ;
++
++import org.seaborne.dboe.base.record.Record ;
++import org.seaborne.dboe.base.record.RecordFactory ;
++
++public class IndexWrapper implements Index {
++ protected final Index index ;
++
++ public IndexWrapper(Index idx) {
++ this.index = idx ;
++ }
++
++ @Override
++ public Record find(Record record) {
++ return index.find(record) ;
++ }
++
++ @Override
++ public boolean contains(Record record) {
++ return index.contains(record) ;
++ }
++
++ @Override
++ public boolean insert(Record record) {
++ return index.insert(record) ;
++ }
++
++ @Override
++ public boolean delete(Record record) {
++ return index.delete(record) ;
++ }
++
++ @Override
++ public Iterator<Record> iterator() {
++ return index.iterator() ;
++ }
++
++ @Override
++ public boolean isEmpty() {
++ return index.isEmpty() ;
++ }
++
++ @Override
++ public void clear() {
++ index.clear() ;
++ }
++
++ @Override
++ public void sync() {
++ index.sync() ;
++ }
++
++ @Override
++ public void close() {
++ index.close() ;
++ }
++
++ @Override
++ public RecordFactory getRecordFactory() {
++ return index.getRecordFactory() ;
++ }
++
++ @Override
++ public void check() {
++ index.check() ;
++ }
++
++ @Override
++ public long size() {
++ return index.size() ;
++ }
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndex.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndex.java
index 0000000,0000000..b53c7f5
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndex.java
@@@ -1,0 -1,0 +1,38 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.index;
++
++import java.util.Iterator ;
++
++import org.seaborne.dboe.base.record.Record ;
++import org.seaborne.dboe.base.record.RecordMapper ;
++
++
++public interface RangeIndex extends Index
++{
++ /** Return records between min (inclusive) and max (exclusive), based on the record keys */
++ public Iterator<Record> iterator(Record recordMin, Record recordMax) ;
++
++ public <X> Iterator<X> iterator(Record recordMin, Record recordMax, RecordMapper<X> mapper) ;
++
++ /** Return the record containing the least key - may or may not have the associated value */
++ public Record minKey() ;
++
++ /** Return the record containing the greatest key - may or may not have the associated value */
++ public Record maxKey() ;
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexLogger.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexLogger.java
index 0000000,0000000..7a7d70d
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexLogger.java
@@@ -1,0 -1,0 +1,71 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.index;
++
++import java.util.Iterator ;
++
++import org.seaborne.dboe.base.record.Record ;
++import org.slf4j.Logger ;
++
++public final class RangeIndexLogger extends RangeIndexWrapper
++{
++ private final Logger log ;
++
++ public RangeIndexLogger(RangeIndex rIdx, Logger log)
++ {
++ super(rIdx) ;
++ this.log = log ;
++ }
++
++ @Override
++ public boolean insert(Record record)
++ {
++ log.info("Add: "+record) ;
++ return super.insert(record) ;
++ }
++
++ @Override
++ public boolean delete(Record record)
++ {
++ log.info("Delete: "+record) ;
++ return super.delete(record) ;
++ }
++
++ @Override
++ public Record find(Record record)
++ {
++ log.info("Find: "+record) ;
++ Record r2 = super.find(record) ;
++ log.info("Find: "+record+" ==> "+r2) ;
++ return r2 ;
++ }
++
++ @Override
++ public Iterator<Record> iterator()
++ {
++ log.info("iterator()") ;
++ return super.iterator() ;
++ }
++
++ @Override
++ public Iterator<Record> iterator(Record minRec, Record maxRec)
++ {
++ log.info("iterator("+minRec+", "+maxRec+")") ;
++ return super.iterator(minRec, maxRec) ;
++ }
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexWrapper.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexWrapper.java
index 0000000,0000000..f5510e5
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexWrapper.java
@@@ -1,0 -1,0 +1,105 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.index;
++
++import java.util.Iterator ;
++
++import org.seaborne.dboe.base.record.Record ;
++import org.seaborne.dboe.base.record.RecordFactory ;
++import org.seaborne.dboe.base.record.RecordMapper ;
++
++public class RangeIndexWrapper implements RangeIndex
++{
++ // Could extend IndexWrapper but it's nice to have one place to look and set breakpoints.
++ protected final RangeIndex rIndex ;
++
++ public RangeIndexWrapper(RangeIndex rIdx) { this.rIndex = rIdx ; }
++
++ @Override
++ public Record find(Record record)
++ { return rIndex.find(record) ; }
++
++ @Override
++ public boolean contains(Record record)
++ { return rIndex.contains(record) ; }
++
++ @Override
++ public Record minKey()
++ { return rIndex.minKey() ; }
++
++ @Override
++ public Record maxKey()
++ { return rIndex.maxKey() ; }
++
++ @Override
++ public boolean insert(Record record)
++ { return rIndex.insert(record) ; }
++
++ @Override
++ public boolean delete(Record record)
++ { return rIndex.delete(record) ; }
++
++// public Record addAndReturnOld(Record record)
++// { return bpt.addAndReturnOld(record) ; }
++
++// public Record deleteAndReturnOld(Record record)
++// { return bpt.deleteAndReturnOld(record) ; }
++
++ @Override
++ public Iterator<Record> iterator()
++ { return rIndex.iterator() ; }
++
++ @Override
++ public Iterator<Record> iterator(Record minRec, Record maxRec)
++ { return rIndex.iterator(minRec, maxRec) ; }
++
++ @Override
++ public <X> Iterator<X> iterator(Record minRec, Record maxRec, RecordMapper<X> mapper)
++ { return rIndex.iterator(minRec, maxRec, mapper) ; }
++
++ @Override
++ public boolean isEmpty()
++ { return rIndex.isEmpty() ; }
++
++ @Override
++ public void clear()
++ { rIndex.clear() ; }
++
++ @Override
++ public void sync()
++ { rIndex.sync() ; }
++
++ @Override
++ public void close()
++ { rIndex.close() ; }
++
++ public RangeIndex getWrapped()
++ { return rIndex ; }
++
++ @Override
++ public RecordFactory getRecordFactory()
++ { return rIndex.getRecordFactory() ; }
++
++ @Override
++ public void check()
++ { rIndex.check() ; }
++
++ @Override
++ public long size()
++ { return rIndex.size() ; }
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-index/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --cc jena-db/dboe-index/src/test/resources/log4j.properties
index 0000000,0000000..d6b299a
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-index/src/test/resources/log4j.properties
@@@ -1,0 -1,0 +1,6 @@@
++log4j.rootLogger=INFO, stdlog
++
++log4j.appender.stdlog=org.apache.log4j.ConsoleAppender
++## log4j.appender.stdlog.target=System.err
++log4j.appender.stdlog.layout=org.apache.log4j.PatternLayout
++log4j.appender.stdlog.layout.ConversionPattern=%d{HH:mm:ss} %-5p %-20c{1} :: %m%n
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-trans-data/pom.xml
----------------------------------------------------------------------
diff --cc jena-db/dboe-trans-data/pom.xml
index 0000000,0000000..50756aa
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-trans-data/pom.xml
@@@ -1,0 -1,0 +1,63 @@@
++<?xml version="1.0" encoding="utf-8"?>
++<!--
++ Licensed 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.
++
++ See the NOTICE file distributed with this work for additional
++ information regarding copyright ownership.
++-->
++
++<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
++ <modelVersion>4.0.0</modelVersion>
++ <artifactId>dboe-trans-data</artifactId>
++ <packaging>jar</packaging>
++ <name>Mantis (${project.artifactId})</name>
++
++ <parent>
++ <groupId>org.seaborne.mantis</groupId>
++ <artifactId>mantis</artifactId>
++ <version>0.3.1-SNAPSHOT</version>
++ </parent>
++
++ <dependencies>
++
++ <dependency>
++ <groupId>org.seaborne.mantis</groupId>
++ <artifactId>dboe-transaction</artifactId>
++ <version>0.3.1-SNAPSHOT</version>
++ </dependency>
++
++ <dependency>
++ <groupId>org.seaborne.mantis</groupId>
++ <artifactId>dboe-index</artifactId>
++ <version>0.3.1-SNAPSHOT</version>
++ </dependency>
++
++ <dependency>
++ <groupId>org.seaborne.mantis</groupId>
++ <artifactId>dboe-index-test</artifactId>
++ <version>0.3.1-SNAPSHOT</version>
++ <scope>test</scope>
++ </dependency>
++
++ <dependency>
++ <groupId>org.seaborne.mantis</groupId>
++ <artifactId>dboe-base</artifactId>
++ <version>0.3.1-SNAPSHOT</version>
++ <classifier>tests</classifier>
++ <scope>test</scope>
++ </dependency>
++
++
++ </dependencies>
++
++</project>
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-trans-data/randtest
----------------------------------------------------------------------
diff --cc jena-db/dboe-trans-data/randtest
index 0000000,0000000..1e716dd
new file mode 100755
--- /dev/null
+++ b/jena-db/dboe-trans-data/randtest
@@@ -1,0 -1,0 +1,57 @@@
++#!/bin/bash
++
++M2="$HOME/.m2/repo"
++
++CPX="
++${M2}/com/fasterxml/jackson/core/jackson-annotations/2.3.0/jackson-annotations-2.3.0.jar
++${M2}/com/fasterxml/jackson/core/jackson-core/2.3.3/jackson-core-2.3.3.jar
++${M2}/com/fasterxml/jackson/core/jackson-databind/2.3.3/jackson-databind-2.3.3.jar
++${M2}/com/github/jsonld-java/jsonld-java/0.5.1/jsonld-java-0.5.1.jar
++${M2}/commons-codec/commons-codec/1.6/commons-codec-1.6.jar
++${M2}/junit/junit/4.12-beta-3/junit-4.12-beta-3.jar
++${M2}/log4j/log4j/1.2.17/log4j-1.2.17.jar
++${M2}/org/apache/commons/commons-csv/1.0/commons-csv-1.0.jar
++${M2}/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2.jar
++${M2}/org/apache/httpcomponents/httpclient-cache/4.2.6/httpclient-cache-4.2.6.jar
++${M2}/org/apache/httpcomponents/httpclient/4.2.6/httpclient-4.2.6.jar
++${M2}/org/apache/httpcomponents/httpcore/4.2.5/httpcore-4.2.5.jar
++${M2}/org/apache/jena/jena-arq/2.13.0-SNAPSHOT/jena-arq-2.13.0-SNAPSHOT.jar
++${M2}/org/apache/jena/jena-core/2.13.0-SNAPSHOT/jena-core-2.13.0-SNAPSHOT.jar
++${M2}/org/apache/jena/jena-iri/1.1.2-SNAPSHOT/jena-iri-1.1.2-SNAPSHOT.jar
++${M2}/org/apache/thrift/libthrift/0.9.2/libthrift-0.9.2.jar
++${M2}/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
++${M2}/org/slf4j/jcl-over-slf4j/1.7.6/jcl-over-slf4j-1.7.6.jar
++${M2}/org/slf4j/slf4j-api/1.7.6/slf4j-api-1.7.6.jar
++${M2}/org/slf4j/slf4j-log4j12/1.7.6/slf4j-log4j12-1.7.6.jar
++${M2}/xerces/xercesImpl/2.11.0/xercesImpl-2.11.0.jar
++${M2}/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar
++"
++
++CP=""
++for x in $CPX
++do
++ if [[ $CP == "" ]]
++ then
++ CP="$x"
++ else
++ CP="$CP:$x"
++ fi
++done
++
++MANTIS="$HOME/Mantis"
++for x in dboe-base dboe-index dboe-index-test dboe-transaction
++do
++ CP="$MANTIS/$x/target/classes:$CP"
++ CP="$MANTIS/$x/target/test-classes:$CP"
++done
++
++ARGS=""
++#ARGS="-Xmx1G"
++ARGS="$ARGS -Dbpt:checking=true"
++ARGS="$ARGS -Dbpt:duplication=true"
++
++
++CP="target/classes:target/test-classes:$CP"
++#echo $CP
++#java -cp "$CP" org.seaborne.dboe.trans.bplustree.rewriter.CmdTestBPlusTreeRewriter "$@"
++java $ARGS -cp "$CP" org.seaborne.dboe.trans.bplustree.soak.CmdTestBPlusTree "$@"
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-trans-data/src/main/java/org/seaborne/dboe/trans/bplustree/AccessPath.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-trans-data/src/main/java/org/seaborne/dboe/trans/bplustree/AccessPath.java
index 0000000,0000000..af62e04
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-trans-data/src/main/java/org/seaborne/dboe/trans/bplustree/AccessPath.java
@@@ -1,0 -1,0 +1,69 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.trans.bplustree;
++
++import java.util.ArrayList ;
++import java.util.List ;
++import java.util.stream.Collectors ;
++
++import org.apache.jena.atlas.lib.InternalErrorException ;
++
++public class AccessPath {
++ static class AccessStep {
++ final BPTreeNode node ;
++ final int idx ;
++ final BPTreePage page ;
++ AccessStep(BPTreeNode node, int idx, BPTreePage page) {
++ this.node = node ;
++ this.idx = idx ;
++ this.page = page ;
++ }
++
++ @Override
++ public String toString() {
++ return "("+node.label()+", "+idx+")->"+page.getId() ;
++ }
++ }
++
++ private final BPTreeNode root ;
++ private List<AccessStep> traversed = new ArrayList<>() ;
++
++ public AccessPath(BPTreeNode root) {
++ this.root = root ;
++ }
++
++ public void add(BPTreeNode node, int idx, BPTreePage page) {
++ traversed.add(new AccessStep(node, idx, page)) ;
++ }
++
++ public void reset(BPTreeNode node, int idx, BPTreePage page) {
++ AccessStep s = traversed.remove(traversed.size()-1) ;
++ AccessStep s2 = new AccessStep(node, idx, page) ;
++ if ( s.node != s2.node )
++ throw new InternalErrorException("Bad attempt to reset: "+this+" with "+s2) ;
++ traversed.add(new AccessStep(node, idx, page)) ;
++ }
++
++ public List<AccessStep> getPath() { return traversed ; }
++
++ @Override
++ public String toString() {
++ return traversed.stream().map(x-> x.toString()).collect(Collectors.toList()).toString() ;
++ }
++}
++
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-trans-data/src/main/java/org/seaborne/dboe/trans/bplustree/BPT.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-trans-data/src/main/java/org/seaborne/dboe/trans/bplustree/BPT.java
index 0000000,0000000..f849367
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-trans-data/src/main/java/org/seaborne/dboe/trans/bplustree/BPT.java
@@@ -1,0 -1,0 +1,248 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.trans.bplustree;
++
++import static java.lang.String.format ;
++import static org.apache.jena.atlas.lib.Alg.decodeIndex ;
++
++import java.util.List ;
++import java.util.Optional ;
++
++import org.apache.jena.atlas.lib.InternalErrorException ;
++import org.apache.jena.atlas.logging.FmtLog ;
++import org.seaborne.dboe.base.block.BlockMgr ;
++import org.seaborne.dboe.base.file.BufferChannel ;
++import org.seaborne.dboe.sys.SystemIndex ;
++import org.seaborne.dboe.trans.bplustree.AccessPath.AccessStep ;
++import org.slf4j.Logger ;
++
++/** B+Tree assist functions */
++public final class BPT {
++ public static boolean Logging = false ; // Turn on/off logging
++
++ public static boolean forcePromoteModes = false ;
++ public static boolean promoteDuplicateRecords = false ;
++ public static boolean promoteDuplicateNodes = false ;
++
++ // Check within BPTreeNode
++ public static boolean CheckingNode = false ;
++ // Check on exit of B+Tree modifiying operations
++ // Not done?
++ public static boolean CheckingConcurrency = SystemIndex.Checking ;
++
++ /** Enable detailed internal consistency checking */
++ public static void checking(boolean onOrOff) {
++ CheckingNode = onOrOff ;
++ }
++
++ /** Dump before and after top level update operations **/
++ public static boolean DumpTree = false ;
++
++ /** Output a lot of detailed information. */
++ public static void infoAll(boolean onOrOff) {
++ DumpTree = true ;
++ Logging = true ;
++ }
++
++ static boolean logging(Logger log) {
++ return Logging && log.isDebugEnabled() ;
++ }
++
++ static void log(Logger log, String fmt, Object... args) {
++ if ( logging(log) ) {
++ FmtLog.debug(log, fmt, args);
++ }
++ }
++
++ static void warning(String msg, Object... args) {
++ msg = format(msg, args) ;
++ System.out.println("Warning: " + msg) ;
++ System.out.flush() ;
++ }
++
++ static void error(String msg, Object... args) {
++ msg = format(msg, args) ;
++ System.out.println() ;
++ System.out.println(msg) ;
++ System.out.flush() ;
++ throw new BPTreeException(msg) ;
++ }
++
++ /** Convert a find index return to the insert location in the array */
++ static int apply(int idx) {
++ if ( idx >= 0 )
++ return idx ;
++ return decodeIndex(idx) ;
++ }
++
++ // ---- Promotion of pages.
++
++ /** Promote a single page. Assumes the path to this page has been handled in some way elsewhere */
++ static boolean promote1(BPTreePage page, BPTreeNode node, int idx) {
++ //System.out.println("promote1: "+page.getBlockMgr().getLabel()+" "+page.getBackingBlock().getId()) ;
++ boolean changed = page.promote() ;
++ node.ptrs.set(idx, page.getId()) ;
++ return changed ;
++ }
++
++ /** Promote a B+Tree root */
++ static boolean promoteRoot(BPTreeNode root) {
++ if ( ! root.isRoot() )
++ throw new InternalErrorException("Not a root") ;
++ boolean changed = root.promote() ;
++ root.bpTree.newRoot(root) ;
++ return changed ;
++ }
++
++ /** Promote a B+Tree page */
++ static void promotePage(AccessPath path, BPTreePage page) {
++ Logger pageLog = page.getLogger() ;
++ boolean loggingCall = logging(pageLog) ;
++ if ( loggingCall )
++ log(pageLog, "Promote :: Path=%s Page=%s", path, page) ;
++ // ---- Checking if the access path is consistent.
++ if ( BPT.CheckingNode && path != null ) {
++ if ( path.getPath().size() > 2) {
++ // Check every one except the last is not a leaf node.
++ List<AccessStep> y = path.getPath().subList(0, path.getPath().size()-2) ;
++ Optional<AccessStep> z = y.stream().filter(e -> e.node.isLeaf() ).findFirst() ;
++ if ( z.isPresent() )
++ error("promote: Leaf %s found in path but not at the tail: %s") ;
++ }
++ // Check the page/index pointers
++ Optional<AccessStep> z2 = path.getPath().stream().filter(e -> e.node.ptrs.get(e.idx) != e.page.getId()).findFirst() ;
++ if ( z2.isPresent() )
++ error("promote: path error: %s in %s", z2.get(), path) ;
++ }
++
++ // ---- Clone the access path nodes.
++ // Path is the route to this page - it does not include this page.
++ // Work from the bottom to the top, the reverse order of AccessPath
++ if ( loggingCall )
++ log(pageLog, " page>> %s", page.label()) ;
++ boolean changed = page.promote();
++ if ( loggingCall ) {
++ if ( changed )
++ log(pageLog, " page<< %s", page.label()) ;
++ else
++ log(pageLog, " .. no change") ;
++ }
++
++ if ( changed )
++ page.write() ; // Being careful.
++
++ // Even if the page did not change, make sure the chain is dealt with.
++ // e.g. promote in place policies.
++ //if ( changed ) {
++ if ( path != null ) {
++ // Sequence of promote1 calls? + root.
++
++ List<AccessStep> steps = path.getPath() ;
++
++ int newPtr = page.getId() ;
++ BPTreePage newPage = null ;
++ boolean previousChanged = changed ;
++ BPTreeNode newRoot = null ;
++
++ if ( logging(pageLog) )
++ log(pageLog, "Path: %s", path) ;
++ // Duplicate from bottom to top.
++ for ( int i = steps.size() - 1 ; i >= 0 ; i-- ) {
++ AccessStep s = steps.get(i) ;
++ // duplicate
++ BPTreeNode n = s.node ;
++ if ( logging(pageLog) )
++ log(pageLog, " >> %s", n) ;
++
++ changed = n.promote() ;
++
++ if ( previousChanged ) {
++ // Even if n did not change, if it's sub changed, need to update s.idx.
++ n.ptrs.set(s.idx, newPtr) ;
++ } else {
++ if ( ! changed ) {
++ if ( logging(pageLog) )
++ log(pageLog, " .. no change") ;
++ continue ;
++ }
++ }
++
++ previousChanged = changed ;
++
++ if ( logging(pageLog) )
++ log(pageLog, " << %s", n) ;
++
++ if ( n.isRoot() ) {
++ if ( newRoot != null)
++ throw new InternalErrorException("New root already found") ;
++ newRoot = n ;
++ }
++ newPtr = n.getId() ;
++ n.write() ;
++
++ }
++ if ( newRoot != null ) {
++ if ( loggingCall )
++ log(pageLog, " new root %s", newRoot) ;
++ page.bpTree.newRoot(newRoot) ;
++ }
++ } // end of "if ( path != null )"
++ }
++
++ /**
++ * The initial tree is a single root node with no records block below it. It
++ * is an illegal tree. We make it by creating a real tree, deleting and
++ * freeing the records block from the root, then resetting the records block
++ * manager. This is to avoid having specialized creating code in
++ * BPlusTreeFactory solely for the rewriter.
++ */
++ public static BPlusTree createRootOnlyBPTree(BPlusTreeParams bptParams,
++ BufferChannel bptState,
++ BlockMgr blkMgrNodes,
++ BlockMgr blkMgrRecords) {
++ BPlusTree bpt = BPlusTreeFactory.createNonTxn(bptParams, bptState, blkMgrNodes, blkMgrRecords) ;
++
++ BPTreeRecordsMgr recordsMgr = bpt.getRecordsMgr() ;
++
++ BPTreeRecords recordsPage = recordsMgr.getWrite(0) ;
++// recordsPage.getRecordBuffer().clear();
++// recordsMgr.write(recordsPage) ;
++ recordsMgr.free(recordsPage);
++// recordsMgr.release(recordsPage);
++ recordsMgr.resetAlloc(0);
++
++ BPTreeNodeMgr nodeMgr = bpt.getNodeManager() ;
++
++ // Alter the root node.
++ BPTreeNode root = nodeMgr.getWrite(BPlusTreeParams.RootId, BPlusTreeParams.RootParent) ;
++ int rootId = root.getId() ;
++ if ( rootId != 0 )
++ throw new BPTreeException("**** Not the root: " + rootId) ;
++
++ // Undo the records block.
++ root.getPtrBuffer().clear() ;
++ root.getRecordBuffer().clear() ;
++ //root.setCount(-1);
++ nodeMgr.write(root);
++ nodeMgr.release(root);
++
++ // Now a broken tree of one root block and no records.
++ return bpt ;
++ }
++}
++
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-trans-data/src/main/java/org/seaborne/dboe/trans/bplustree/BPTStateMgr.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-trans-data/src/main/java/org/seaborne/dboe/trans/bplustree/BPTStateMgr.java
index 0000000,0000000..cb7049c
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-trans-data/src/main/java/org/seaborne/dboe/trans/bplustree/BPTStateMgr.java
@@@ -1,0 -1,0 +1,89 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.trans.bplustree;
++
++import org.apache.jena.atlas.logging.FmtLog ;
++import org.seaborne.dboe.base.file.BufferChannel ;
++import org.seaborne.dboe.transaction.txn.StateMgrData ;
++import org.slf4j.Logger ;
++import org.slf4j.LoggerFactory ;
++
++/** Manage the persistent state of the tree
++ *
++ * This consists of last commited root, and the limits on the blocks for both
++ * nodes and records.
++ *
++ * (rootId/int-as-long, nodeAllocLimit/long, recordsAllocLimit/long)
++ */
++public class BPTStateMgr extends StateMgrData {
++ private static Logger log = LoggerFactory.getLogger(BPTStateMgr.class) ;
++
++ private static int idxRoot = 0 ;
++ private static int idxNodeBlocksLimit = 1 ;
++ private static int idxRecordsBlocksLimit = 2 ;
++
++ private int currentRoot() { return (int)super.get(idxRoot) ; }
++ private long nodeBlocksLimit() { return super.get(idxNodeBlocksLimit) ; }
++ private long recordsBlocksLimit() { return super.get(idxRecordsBlocksLimit) ; }
++
++ private void currentRoot(int x) { super.set(idxRoot, x) ; }
++ private void nodeBlocksLimit(long x) { super.set(idxNodeBlocksLimit, x) ; }
++ private void recordsBlocksLimit(long x) { super.set(idxRecordsBlocksLimit, x) ; }
++
++ private boolean LOGGING = BPT.Logging ;
++
++ public BPTStateMgr(BufferChannel storage) {
++ // These values are the values for a null tree (no blocks).
++ super(storage, 0L, 0L, 0L) ;
++ }
++
++ /*package*/ void setState(int rootIdx, long nodeBlkLimit, long recordsBlkLimit) {
++ currentRoot(rootIdx) ;
++ nodeBlocksLimit(nodeBlkLimit) ;
++ recordsBlocksLimit(recordsBlkLimit) ;
++ log("Set") ;
++ setDirtyFlag() ;
++ // But don't write it.
++ }
++ @Override
++ protected void writeStateEvent() {
++ log("Write") ;
++ }
++
++ @Override
++ protected void readStateEvent() {
++ log("Read") ;
++ }
++
++ private void log(String operation) {
++ if ( LOGGING )
++ FmtLog.info(log, "%s state: root=%d // node block limit = %d // records block limit %d", operation, currentRoot(), nodeBlocksLimit(), recordsBlocksLimit()) ;
++ }
++
++ public int getRoot() {
++ return currentRoot() ;
++ }
++
++ public long getNodeBlocksLimit() {
++ return nodeBlocksLimit() ;
++ }
++
++ public long getRecordsBlocksLimit() {
++ return recordsBlocksLimit() ;
++ }
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/dboe-trans-data/src/main/java/org/seaborne/dboe/trans/bplustree/BPTreeException.java
----------------------------------------------------------------------
diff --cc jena-db/dboe-trans-data/src/main/java/org/seaborne/dboe/trans/bplustree/BPTreeException.java
index 0000000,0000000..423785a
new file mode 100644
--- /dev/null
+++ b/jena-db/dboe-trans-data/src/main/java/org/seaborne/dboe/trans/bplustree/BPTreeException.java
@@@ -1,0 -1,0 +1,26 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.dboe.trans.bplustree;
++
++import org.seaborne.dboe.DBOpEnvException ;
++
++public class BPTreeException extends DBOpEnvException
++{
++ public BPTreeException() {}
++ public BPTreeException(String msg) { super(msg) ; }
++}