summaryrefslogtreecommitdiffstats
path: root/persistence
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@oath.com>2017-10-09 12:32:42 +0000
committerTor Egge <Tor.Egge@oath.com>2017-10-09 13:30:09 +0000
commit611ae4f7ca9c53c86540e48a7f3a49093a43e64b (patch)
treef93c0889c33ae22cfcc9680eccd881e9c73b9740 /persistence
parentfe8b4bfa8929ed37d4318ae0c42a96533811af42 (diff)
Remove unused java persistence implementation.
Diffstat (limited to 'persistence')
-rw-r--r--persistence/CMakeLists.txt3
-rw-r--r--persistence/pom.xml105
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/rpc/BucketProviderMethod.java22
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/rpc/PersistenceProviderHandler.java401
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/rpc/PersistenceProviderMethod.java39
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/rpc/RPCHandler.java39
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/rpc/TimestampedProviderMethod.java20
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/rpc/package-info.java7
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/AbstractPersistenceProvider.java82
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/Bucket.java30
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/BucketInfo.java155
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/ClusterState.java32
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/ClusterStateImpl.java50
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/DocEntry.java56
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/PartitionState.java27
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/PersistenceProvider.java382
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/Selection.java70
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/conformance/ConformanceTest.java1605
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/conformance/TestDocMan.java37
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/conformance/package-info.java7
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/package-info.java7
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/result/BucketIdListResult.java36
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/result/BucketInfoResult.java37
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/result/CreateIteratorResult.java33
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/result/GetResult.java60
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/result/IterateResult.java43
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/result/PartitionStateListResult.java37
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/result/RemoveResult.java47
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/result/Result.java83
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/result/UpdateResult.java39
-rw-r--r--persistence/src/main/java/com/yahoo/persistence/spi/result/package-info.java7
-rw-r--r--persistence/src/main/resources/configdefinitions/persistence-rpc.def4
32 files changed, 0 insertions, 3602 deletions
diff --git a/persistence/CMakeLists.txt b/persistence/CMakeLists.txt
index d868bfcba6e..983a0a390a0 100644
--- a/persistence/CMakeLists.txt
+++ b/persistence/CMakeLists.txt
@@ -27,6 +27,3 @@ vespa_define_module(
src/tests/dummyimpl
src/tests/spi
)
-
-install_fat_java_artifact(persistence)
-install_config_definition(src/main/resources/configdefinitions/persistence-rpc.def persistence.persistence-rpc.def)
diff --git a/persistence/pom.xml b/persistence/pom.xml
deleted file mode 100644
index 00734aa2f89..00000000000
--- a/persistence/pom.xml
+++ /dev/null
@@ -1,105 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
-<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>
- <parent>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>parent</artifactId>
- <version>6-SNAPSHOT</version>
- </parent>
- <artifactId>persistence</artifactId>
- <packaging>container-plugin</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>bundle-plugin</artifactId>
- <extensions>true</extensions>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <compilerArgs>
- <arg>-Xlint:rawtypes</arg>
- <arg>-Xlint:unchecked</arg>
- <arg>-Xlint:deprecation</arg>
- <arg>-Werror</arg>
- </compilerArgs>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-javadocs</id>
- <goals>
- <goal>jar</goal>
- </goals>
- <configuration>
- <finalName>${project.artifactId}</finalName>
- <additionalparam>-Xdoclint:${doclint} -Xdoclint:-missing</additionalparam>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-source-plugin</artifactId>
- <version>2.1.2</version>
- <executions>
- <execution>
- <id>attach-sources</id>
- <goals>
- <goal>jar-no-fork</goal>
- </goals>
- <configuration>
- <finalName>${project.artifactId}</finalName>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
-
- <dependency>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>container-dev</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- <exclusions>
- <exclusion>
- <groupId>org.antlr</groupId>
- <artifactId>antlr4-runtime</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>document</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>jrt</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
-</project>
diff --git a/persistence/src/main/java/com/yahoo/persistence/rpc/BucketProviderMethod.java b/persistence/src/main/java/com/yahoo/persistence/rpc/BucketProviderMethod.java
deleted file mode 100644
index a5a13d7bf0e..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/rpc/BucketProviderMethod.java
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.rpc;
-
-/**
- * Class to represent a persistence provider method that has a bucket
- * as its first parameter.
- */
-public class BucketProviderMethod extends PersistenceProviderMethod {
- public BucketProviderMethod(String name, PersistenceProviderHandler owner) {
- this(name, owner, "", "");
- }
-
- public BucketProviderMethod(String name, PersistenceProviderHandler owner, String paramTypes) {
- this(name, owner, paramTypes, "");
- }
-
- public BucketProviderMethod(String name, PersistenceProviderHandler owner, String paramTypes, String returnTypes) {
- super(name, owner, "ll" + paramTypes, returnTypes);
- paramDesc("bucketId", "The bucket id to perform operation on");
- paramDesc("partitionId", "The partition to perform operation on");
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/rpc/PersistenceProviderHandler.java b/persistence/src/main/java/com/yahoo/persistence/rpc/PersistenceProviderHandler.java
deleted file mode 100644
index e4a5dc3067f..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/rpc/PersistenceProviderHandler.java
+++ /dev/null
@@ -1,401 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.rpc;
-
-import com.yahoo.document.*;
-import com.yahoo.document.fieldset.AllFields;
-import com.yahoo.document.fieldset.FieldSet;
-import com.yahoo.document.select.parser.ParseException;
-import com.yahoo.document.serialization.*;
-import com.yahoo.io.GrowableByteBuffer;
-import com.yahoo.jrt.*;
-import com.yahoo.persistence.PersistenceRpcConfig;
-import com.yahoo.persistence.spi.*;
-import com.yahoo.persistence.spi.result.*;
-
-import java.nio.ByteBuffer;
-import java.util.TreeSet;
-
-/**
- * @author thomasg
- */
-public class PersistenceProviderHandler extends RPCHandler {
- DocumentTypeManager docTypeManager;
- PersistenceProvider provider = null;
- boolean started = false;
-
- int magic_number = 0xf00ba2;
-
- public PersistenceProviderHandler(PersistenceRpcConfig config) {
- super(config.port());
- }
-
- public void initialize(PersistenceProvider provider, DocumentTypeManager manager) {
- this.provider = provider;
- this.docTypeManager = manager;
-
- if (!started) {
- addMethod(new Method("vespa.persistence.connect", "s", "", this, "RPC_connect")
- .paramDesc(0, "buildId", "Id to make sure client and server come from the same build"));
- addMethod(new PersistenceProviderMethod("initialize", this));
- addMethod(new PersistenceProviderMethod("getPartitionStates", this, "", "IS"));
- addMethod(new PersistenceProviderMethod("listBuckets", this, "l", "L")
- .paramDesc("partitionId", "The partition to list buckets for")
- .returnDesc("bucketIds", "An array of bucketids"));
- addMethod(new PersistenceProviderMethod("getModifiedBuckets", this, "", "L")
- .returnDesc("bucketIds", "An array of bucketids"));
- addMethod(new PersistenceProviderMethod("setClusterState", this, "x")
- .paramDesc("clusterState", "The updated cluster state"));
- addMethod(new BucketProviderMethod("setActiveState", this, "b")
- .paramDesc("bucketState", "The new state (active/not active)"));
- addMethod(new BucketProviderMethod("getBucketInfo", this, "", "iiiiibb")
- .returnDesc("checksum", "The bucket checksum")
- .returnDesc("documentCount", "The number of unique documents stored in the bucket")
- .returnDesc("documentSize", "The size of the unique documents")
- .returnDesc("entryCount", "The number of entries (inserts/removes) in the bucket")
- .returnDesc("usedSize", "The number of bytes used by the bucket in total")
- .returnDesc("ready", "Whether the bucket is \"ready\" for external reads or not")
- .returnDesc("active", "Whether the bucket has been activated for external reads or not"));
- addMethod(new TimestampedProviderMethod("put", this, "x")
- .paramDesc("document", "The serialized document"));
- addMethod(new TimestampedProviderMethod("removeById", this, "s", "b")
- .paramDesc("documentId", "The ID of the document to remove")
- .returnDesc("existed", "Whether or not the document existed"));
- addMethod(new TimestampedProviderMethod("removeIfFound", this, "s", "b")
- .paramDesc("documentId", "The ID of the document to remove")
- .returnDesc("existed", "Whether or not the document existed"));
- addMethod(new TimestampedProviderMethod("update", this, "x", "l")
- .paramDesc("update", "The document update to apply")
- .returnDesc("existingTimestamp", "The timestamp of the document that the update was applied to, or 0 if it didn't exist"));
- addMethod(new BucketProviderMethod("flush", this));
- addMethod(new BucketProviderMethod("get", this, "ss", "lx")
- .paramDesc("fieldSet", "A set of fields to return")
- .paramDesc("documentId", "The document ID to fetch")
- .returnDesc("timestamp", "The timestamp of the document fetched")
- .returnDesc("document", "A serialized document"));
- addMethod(new BucketProviderMethod("createIterator", this, "ssllLb", "l")
- .paramDesc("fieldSet", "A set of fields to return")
- .paramDesc("documentSelectionString", "Document selection to match with")
- .paramDesc("timestampFrom", "lowest timestamp to include")
- .paramDesc("timestampTo", "Highest timestamp to include")
- .paramDesc("timestampSubset", "Array of timestamps to include")
- .paramDesc("includedVersions", "Document versions to include")
- .returnDesc("iteratorId", "An iterator id to use for further calls to iterate and destroyIterator"));
- addMethod(new PersistenceProviderMethod("iterate", this, "ll", "LISXb")
- .paramDesc("iteratorId", "An iterator id previously returned by createIterator")
- .paramDesc("maxByteSize", "The maximum number of bytes to return in this call (approximate)")
- .returnDesc("timestampArray", "Array of timestamps for DocEntries")
- .returnDesc("flagArray", "Array of flags for DocEntries")
- .returnDesc("docIdArray", "Array of document ids for DocEntries")
- .returnDesc("docArray", "Array of documents for DocEntries")
- .returnDesc("completed", "Whether or not iteration completed"));
- addMethod(new PersistenceProviderMethod("destroyIterator", this, "l")
- .paramDesc("iteratorId", "An iterator id previously returned by createIterator"));
- addMethod(new BucketProviderMethod("createBucket", this));
- addMethod(new BucketProviderMethod("deleteBucket", this));
- addMethod(new BucketProviderMethod("split", this, "llll")
- .paramDesc("target1Bucket", "Bucket id of first split target")
- .paramDesc("target1Partition", "Partition id of first split target")
- .paramDesc("target2Bucket", "Bucket id of second split target")
- .paramDesc("target2Partition", "Partition id of second split target"));
- addMethod(new PersistenceProviderMethod("join", this, "llllll")
- .paramDesc("source1Bucket", "Bucket id of first source bucket")
- .paramDesc("source1Partition", "Partition id of first source bucket")
- .paramDesc("source1Bucket", "Bucket id of second source bucket")
- .paramDesc("source1Partition", "Partition id of second source bucket")
- .paramDesc("source1Bucket", "Bucket id of target bucket")
- .paramDesc("source1Partition", "Partition id of target bucket"));
- addMethod(new BucketProviderMethod("move", this, "l")
- .paramDesc("partitionId", "The partition to move the bucket to"));
- addMethod(new BucketProviderMethod("maintain", this, "b")
- .paramDesc("maintenanceLevel", "LOW or HIGH maintenance"));
- addMethod(new TimestampedProviderMethod("removeEntry", this));
-
- start();
- started = false;
- }
- }
-
- public void RPC_connect(Request req) {
- }
-
- public void addResult(Result result, Request req) {
- req.returnValues().add(new Int8Value((byte) result.getErrorType().ordinal()));
- req.returnValues().add(new StringValue(result.getErrorMessage()));
- }
-
- public void RPC_initialize(Request req) {
- addResult(provider.initialize(), req);
- }
-
- public void RPC_getPartitionStates(Request req) {
- PartitionStateListResult result = provider.getPartitionStates();
- addResult(result, req);
-
- int[] states = new int[result.getPartitionStates().size()];
- String[] reasons = new String[result.getPartitionStates().size()];
-
- for (int i = 0; i < states.length; ++i) {
- states[i] = result.getPartitionStates().get(i).getState().ordinal();
- reasons[i] = result.getPartitionStates().get(i).getReason();
- }
-
- req.returnValues().add(new Int32Array(states));
- req.returnValues().add(new StringArray(reasons));
- }
-
- void addBucketIdListResult(BucketIdListResult result, Request req) {
- addResult(result, req);
-
- long[] retVal = new long[result.getBuckets().size()];
- for (int i = 0; i < retVal.length; ++i) {
- retVal[i] = result.getBuckets().get(i).getRawId();
- }
-
- req.returnValues().add(new Int64Array(retVal));
- }
-
- public void RPC_listBuckets(Request req) {
- addBucketIdListResult(provider.listBuckets((short) req.parameters().get(0).asInt64()), req);
- }
-
- public void RPC_setClusterState(Request req) throws java.text.ParseException {
- ClusterStateImpl state = new ClusterStateImpl(req.parameters().get(0).asData());
- addResult(provider.setClusterState(state), req);
- }
-
- Bucket getBucket(Request req, int index) {
- return new Bucket((short)req.parameters().get(index + 1).asInt64(),
- new BucketId(req.parameters().get(index).asInt64()));
- }
-
- public void RPC_setActiveState(Request req) {
- try {
- addResult(provider.setActiveState(getBucket(req, 0),
- BucketInfo.ActiveState.values()[req.parameters().get(2).asInt8()]), req);
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- public void RPC_getBucketInfo(Request req) {
- BucketInfoResult result = provider.getBucketInfo(getBucket(req, 0));
-
- addResult(result, req);
- req.returnValues().add(new Int32Value(result.getBucketInfo().getChecksum()));
- req.returnValues().add(new Int32Value(result.getBucketInfo().getDocumentCount()));
- req.returnValues().add(new Int32Value(result.getBucketInfo().getDocumentSize()));
- req.returnValues().add(new Int32Value(result.getBucketInfo().getEntryCount()));
- req.returnValues().add(new Int32Value(result.getBucketInfo().getUsedSize()));
- req.returnValues().add(new Int8Value(result.getBucketInfo().isReady() ? (byte)1 : (byte)0));
- req.returnValues().add(new Int8Value(result.getBucketInfo().isActive() ? (byte)1 : (byte)0));
- }
-
- public void RPC_put(Request req) {
- try {
- GrowableByteBuffer buffer = new GrowableByteBuffer(ByteBuffer.wrap(req.parameters().get(3).asData()));
- Document doc = new Document(DocumentDeserializerFactory.create42(docTypeManager, buffer));
- addResult(provider.put(getBucket(req, 0), req.parameters().get(2).asInt64(), doc), req);
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- public void addRemoveResult(RemoveResult result, Request req) {
- addResult(result, req);
- req.returnValues().add(new Int8Value(result.wasFound() ? (byte)1 : (byte)0));
- }
-
- public void RPC_removeById(Request req) {
- addRemoveResult(
- provider.remove(
- getBucket(req, 0),
- req.parameters().get(2).asInt64(),
- new DocumentId(req.parameters().get(3).asString())), req);
- }
-
- public void RPC_removeIfFound(Request req) {
- addRemoveResult(
- provider.removeIfFound(
- getBucket(req, 0),
- req.parameters().get(2).asInt64(),
- new DocumentId(req.parameters().get(3).asString())), req);
- }
-
- public void RPC_removeEntry(Request req) {
- addResult(
- provider.removeEntry(
- getBucket(req, 0),
- req.parameters().get(2).asInt64()), req);
- }
-
- public void RPC_update(Request req) {
- try {
- GrowableByteBuffer buffer = new GrowableByteBuffer(ByteBuffer.wrap(req.parameters().get(3).asData()));
- DocumentUpdate update = new DocumentUpdate(DocumentDeserializerFactory.createHead(docTypeManager, buffer));
- UpdateResult result = provider.update(getBucket(req, 0), req.parameters().get(2).asInt64(), update);
- addResult(result, req);
-
- req.returnValues().add(new Int64Value(result.getExistingTimestamp()));
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- public void RPC_flush(Request req) {
- addResult(provider.flush(getBucket(req, 0)), req);
- }
-
- FieldSet getFieldSet(Request req, int index) {
- return new AllFields();
-
- //return new FieldSetRepo().parse(docTypeManager, req.parameters().get(index).asString());
- }
-
- byte[] serializeDocument(Document doc) {
- if (doc != null) {
- GrowableByteBuffer buf = new GrowableByteBuffer();
- DocumentSerializer serializer = DocumentSerializerFactory.create42(buf);
- doc.serialize(serializer);
- buf.flip();
- return buf.array();
- } else {
- return new byte[0];
- }
- }
-
- public void RPC_get(Request req) {
- GetResult result = provider.get(getBucket(req, 0),
- getFieldSet(req, 2),
- new DocumentId(req.parameters().get(3).asString()));
- addResult(result, req);
- req.returnValues().add(new Int64Value(result.getLastModifiedTimestamp()));
- req.returnValues().add(new DataValue(serializeDocument(result.getDocument())));
- }
-
- public void RPC_createIterator(Request req) {
- try {
- TreeSet<Long> timestampSet = new TreeSet<Long>();
- long[] timestamps = req.parameters().get(6).asInt64Array();
- for (long l : timestamps) {
- timestampSet.add(l);
- }
-
- Selection selection;
- if (timestamps.length > 0) {
- selection = new Selection(timestampSet);
- } else {
- selection = new Selection(
- req.parameters().get(3).asString(),
- req.parameters().get(4).asInt64(),
- req.parameters().get(5).asInt64());
- }
-
- CreateIteratorResult result = provider.createIterator(
- getBucket(req, 0),
- getFieldSet(req, 2),
- selection,
- PersistenceProvider.IncludedVersions.values()[req.parameters().get(7).asInt8()]);
-
- addResult(result, req);
- req.returnValues().add(new Int64Value(result.getIteratorId()));
- } catch (ParseException e) {
- addResult(new Result(Result.ErrorType.PERMANENT_ERROR, "Unparseable document selection expression"), req);
- req.returnValues().add(new Int64Value(0));
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- public void RPC_iterate(Request req) {
- try {
- long iteratorId = req.parameters().get(0).asInt64();
- long maxByteSize = req.parameters().get(1).asInt64();
-
- IterateResult result = provider.iterate(iteratorId, maxByteSize);
-
- addResult(result, req);
-
- int count = result.getEntries() != null ? result.getEntries().size() : 0;
- long[] timestamps = new long[count];
- int[] flags = new int[count];
- String[] docIds = new String[count];
- byte[][] documents = new byte[count][];
-
- for (int i = 0; i < count; ++i) {
- DocEntry entry = result.getEntries().get(i);
- timestamps[i] = entry.getTimestamp();
- flags[i] = entry.getType().ordinal();
-
- if (entry.getDocumentId() != null) {
- docIds[i] = entry.getDocumentId().toString();
- } else {
- docIds[i] = "";
- }
-
- if (entry.getDocument() != null) {
- documents[i] = serializeDocument(entry.getDocument());
- } else {
- documents[i] = (new byte[0]);
- }
- }
-
- req.returnValues().add(new Int64Array(timestamps));
- req.returnValues().add(new Int32Array(flags));
- req.returnValues().add(new StringArray(docIds));
- req.returnValues().add(new DataArray(documents));
- req.returnValues().add(new Int8Value(result.isCompleted() ? (byte)1 : (byte)0));
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- public void RPC_destroyIterator(Request req) {
- try {
- addResult(provider.destroyIterator(req.parameters().get(0).asInt64()), req);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void RPC_createBucket(Request req) {
- addResult(provider.createBucket(getBucket(req, 0)), req);
- }
-
- public void RPC_deleteBucket(Request req) {
- addResult(provider.deleteBucket(getBucket(req, 0)), req);
- }
-
- public void RPC_getModifiedBuckets(Request req) {
- addBucketIdListResult(provider.getModifiedBuckets(), req);
- }
-
- public void RPC_maintain(Request req) {
- addResult(provider.maintain(getBucket(req, 0),
- PersistenceProvider.MaintenanceLevel.values()[req.parameters().get(2).asInt8()]), req);
- }
-
- public void RPC_split(Request req) {
- addResult(provider.split(
- getBucket(req, 0),
- getBucket(req, 2),
- getBucket(req, 4)), req);
- }
-
- public void RPC_join(Request req) {
- addResult(provider.join(
- getBucket(req, 0),
- getBucket(req, 2),
- getBucket(req, 4)), req);
- }
-
- public void RPC_move(Request req) {
- addResult(provider.move(
- getBucket(req, 0),
- (short)req.parameters().get(2).asInt64()), req);
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/rpc/PersistenceProviderMethod.java b/persistence/src/main/java/com/yahoo/persistence/rpc/PersistenceProviderMethod.java
deleted file mode 100644
index da0bf786a29..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/rpc/PersistenceProviderMethod.java
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.rpc;
-
-import com.yahoo.jrt.*;
-
-/**
- * Class to represent a JRT method used by PersistenceProviderHandler.
- */
-public class PersistenceProviderMethod extends Method {
- int nextReturnDesc = 0;
- int nextParamDesc;
-
- PersistenceProviderMethod returnDesc(String code, String text) {
- returnDesc(nextReturnDesc, code, text);
- ++nextReturnDesc;
- return this;
- }
-
- PersistenceProviderMethod paramDesc(String code, String text) {
- paramDesc(nextParamDesc, code, text);
- ++nextParamDesc;
- return this;
- }
-
- public PersistenceProviderMethod(String name, PersistenceProviderHandler owner, String paramTypes) {
- this(name, owner, paramTypes, "");
- }
-
- public PersistenceProviderMethod(String name, PersistenceProviderHandler owner) {
- this(name, owner, "", "");
- }
-
- public PersistenceProviderMethod(String name, PersistenceProviderHandler owner, String paramTypes, String returnTypes) {
- super("vespa.persistence." + name, paramTypes, "bs" + returnTypes, owner, "RPC_" + name);
- returnDesc("code", "Error code, or 0 if successful");
- returnDesc("message", "Error message");
- }
-
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/rpc/RPCHandler.java b/persistence/src/main/java/com/yahoo/persistence/rpc/RPCHandler.java
deleted file mode 100644
index b28579cd28e..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/rpc/RPCHandler.java
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.rpc;
-
-import com.yahoo.jrt.*;
-
-import java.util.logging.Logger;
-
-
-/**
- * A handler that can be used to register RPC function calls,
- * using Vespa JRT. To enable an RPC server, first call addMethod() any number of times,
- * then start().
- */
-public class RPCHandler {
- private final static Logger log = Logger.getLogger(RPCHandler.class.getName());
-
- private final int port;
- private final Supervisor supervisor;
- private Acceptor acceptor;
-
- public RPCHandler(int port) {
- supervisor = new Supervisor(new Transport());
- this.port = port;
- }
-
- public void start() {
- try {
- acceptor = supervisor.listen(new Spec(port));
- log.info("Listening for RPC requests on port " + port);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- public void addMethod(Method method) {
- supervisor.addMethod(method);
- }
-
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/rpc/TimestampedProviderMethod.java b/persistence/src/main/java/com/yahoo/persistence/rpc/TimestampedProviderMethod.java
deleted file mode 100644
index 00639601c4d..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/rpc/TimestampedProviderMethod.java
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.rpc;
-
-/**
- * Represents a JRT persistence provider method that includes a timestamp in its request
- */
-public class TimestampedProviderMethod extends BucketProviderMethod {
- public TimestampedProviderMethod(String name, PersistenceProviderHandler owner) {
- this(name, owner, "", "");
- }
-
- public TimestampedProviderMethod(String name, PersistenceProviderHandler owner, String paramTypes) {
- this(name, owner, paramTypes, "");
- }
-
- public TimestampedProviderMethod(String name, PersistenceProviderHandler owner, String paramTypes, String returnTypes) {
- super(name, owner, "l" + paramTypes, returnTypes);
- paramDesc("timestamp", "The timestamp of the operation");
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/rpc/package-info.java b/persistence/src/main/java/com/yahoo/persistence/rpc/package-info.java
deleted file mode 100644
index 2d0b9fea6b7..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/rpc/package-info.java
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-@ExportPackage
-@PublicApi
-package com.yahoo.persistence.rpc;
-
-import com.yahoo.api.annotations.PublicApi;
-import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/AbstractPersistenceProvider.java b/persistence/src/main/java/com/yahoo/persistence/spi/AbstractPersistenceProvider.java
deleted file mode 100644
index bd7c2bd7823..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/AbstractPersistenceProvider.java
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi;
-
-import com.yahoo.document.*;
-import com.yahoo.document.fieldset.AllFields;
-import com.yahoo.persistence.spi.*;
-import com.yahoo.persistence.spi.result.*;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * An abstract class that implements persistence provider functionality that some providers
- * may not have use for.
- */
-public abstract class AbstractPersistenceProvider implements PersistenceProvider {
- @Override
- public Result initialize() {
- return new Result();
- }
-
- @Override
- public PartitionStateListResult getPartitionStates() {
- List<PartitionState> partitionStates = new ArrayList<PartitionState>();
- partitionStates.add(new PartitionState(PartitionState.State.UP, ""));
- return new PartitionStateListResult(partitionStates);
- }
-
- @Override
- public Result setClusterState(ClusterState state) {
- return new Result();
- }
-
- @Override
- public Result setActiveState(Bucket bucket, BucketInfo.ActiveState active) {
- return new Result();
- }
-
-
- @Override
- public RemoveResult removeIfFound(Bucket bucket, long timestamp, DocumentId id) {
- return remove(bucket, timestamp, id);
- }
-
- @Override
- public Result removeEntry(Bucket bucket, long timestampToRemove) {
- return new Result();
- }
-
- @Override
- public Result flush(Bucket bucket) {
- return new Result();
- }
-
- @Override
- public BucketIdListResult getModifiedBuckets() {
- return new BucketIdListResult(new ArrayList<BucketId>());
- }
-
- @Override
- public Result maintain(Bucket bucket, MaintenanceLevel level) {
- return new Result();
- }
-
- @Override
- public Result move(Bucket bucket, short partitionId) {
- return new Result();
- }
-
- @Override
- public UpdateResult update(Bucket bucket, long timestamp, DocumentUpdate update) {
- GetResult result = get(bucket, new AllFields(), update.getId());
- if (result.wasFound()) {
- Document doc = result.getDocument().clone();
- update.applyTo(doc);
- put(bucket, timestamp, doc);
- return new UpdateResult(result.getLastModifiedTimestamp());
- } else {
- return new UpdateResult();
- }
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/Bucket.java b/persistence/src/main/java/com/yahoo/persistence/spi/Bucket.java
deleted file mode 100644
index ed443fa9100..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/Bucket.java
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi;
-
-import com.yahoo.document.BucketId;
-
-/**
- * @author thomasg
- */
-public class Bucket {
- BucketId bucketId;
- short partitionId;
-
- /**
- * @param partition The partition (i.e. disk) where the bucket is located
- * @param bucketId The bucket id of the bucket
- */
- public Bucket(short partition, BucketId bucketId) {
- this.partitionId = partition;
- this.bucketId = bucketId;
- }
-
- public BucketId getBucketId() { return bucketId; }
-
- public short getPartitionId() { return partitionId; }
-
- @Override
- public String toString() {
- return partitionId + "/" + bucketId;
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/BucketInfo.java b/persistence/src/main/java/com/yahoo/persistence/spi/BucketInfo.java
deleted file mode 100644
index 2105ade6206..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/BucketInfo.java
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi;
-
-/**
- * Class to represents information about the buckets stored by the persistence provider.
- */
-public class BucketInfo {
- public enum ReadyState {
- NOT_READY,
- READY
- }
-
- public enum ActiveState {
- NOT_ACTIVE,
- ACTIVE
- }
-
- /** Create an empty bucket info object. */
- public BucketInfo() {
- }
-
- /**
- * @param checksum The checksum of the bucket contents.
- * @param docCount The number of documents stored
- * @param docSize The total size of the documents stored
- * @param metaEntryCount The number of different versions of documents that are stored (including document removes)
- * @param size The total size of entries in this bucket.
- * @param ready Whether the bucket is ready or not
- * @param active Whether the bucket is active or not
- */
- public BucketInfo(int checksum,
- int docCount,
- int docSize,
- int metaEntryCount,
- int size,
- ReadyState ready,
- ActiveState active) {
- this.checksum = checksum;
- this.documentCount = docCount;
- this.documentSize = docSize;
- this.entryCount = metaEntryCount;
- this.size = size;
- this.ready = ready;
- this.active = active;
- }
-
- /**
- * Constructor for bucketinfo for providers that don't care about the READY/ACTIVE paradigm.
- *
- * @param checksum The checksum of the bucket contents.
- * @param docCount The number of documents stored
- * @param docSize The total size of the documents stored
- * @param metaEntryCount The number of different versions of documents that are stored (including document removes)
- * @param size The total size of entries in this bucket.
- */
- public BucketInfo(int checksum,
- int docCount,
- int docSize,
- int metaEntryCount,
- int size) {
- this(checksum, docCount, docSize, metaEntryCount, size, ReadyState.NOT_READY, ActiveState.NOT_ACTIVE);
- }
-
- public boolean equals(BucketInfo other) {
- return checksum == other.checksum &&
- documentCount == other.documentCount &&
- documentSize == other.documentSize &&
- entryCount == other.entryCount &&
- size == other.size &&
- ready == other.ready &&
- active == other.active;
- }
-
- @Override
- public String toString() {
- String retVal = "BucketInfo(";
- if (valid()) {
- retVal += "crc " + checksum + ", uniqueCount " + documentCount +
- ", uniqueSize " + documentSize + ", entry count " + entryCount +
- ", usedSize " + size + ", ready " + isReady() +
- ", active " + isActive();
- } else {
- retVal += "invalid";
- }
- retVal += ")";
- return retVal;
- }
-
- /**
- * @return Get the checksum of the bucket. An empty bucket should have checksum of
- * zero. The checksum should only include data from the latest versions of
- * non-removed documents. Otherwise, the checksum implementation is up to
- * the persistence implementation. (Unless one wants to run multiple
- * persistence implementations in the same cluster, in which case they have
- * to match).
- */
- public int getChecksum() { return checksum; }
-
- /**
- * The number of unique documents that have not been removed from the
- * bucket. A unique document count above the splitting threshold will cause
- * the bucket to be split.
- */
- public int getDocumentCount() { return documentCount; }
-
- /**
- * The total size of all the unique documents in this bucket. A size above
- * the splitting threshold will cause the bucket to be split. Knowing size
- * is optional, but a bucket with more than zero unique documents should
- * always return a non-zero value for size. If splitting on size is not
- * required or desired, a simple solution here is to just set the number
- * of unique documents as the size.
- */
- public int getDocumentSize() { return documentSize; }
-
- /**
- * The number of meta entries in the bucket. For a persistence layer
- * keeping history of data (multiple versions of a document or remove
- * entries), it may use more meta entries in the bucket than it has unique
- * documents If the sum of meta entries from a pair of joinable buckets go
- * below the join threshold, the buckets will be joined.
- */
- public int getEntryCount() { return entryCount; }
-
- /**
- * The total size used by the persistence layer to store all the documents
- * for a given bucket. Possibly excluding pre-allocated space not currently
- * in use. Knowing size is optional, but if the bucket contains more than
- * zero meta entries, it should return a non-zero value for used size.
- */
- public int getUsedSize() { return size; }
-
- /**
- * @return Returns true if this bucket is considered "ready". Ready buckets
- * are prioritized before non-ready buckets to be set active.
- */
- public boolean isReady() { return ready == ReadyState.READY; }
-
- /**
- * @return Returns true if this bucket is "active". If it is, the bucket should
- * be included in read operations outside of the persistence provider API.
- */
- public boolean isActive() { return active == ActiveState.ACTIVE; }
-
- public boolean valid()
- { return (documentCount > 0 || documentSize == 0); }
-
- int checksum = 0;
- int documentCount = 0;
- int documentSize = 0;
- int entryCount = 0;
- int size = 0;
- ReadyState ready = ReadyState.READY;
- ActiveState active = ActiveState.NOT_ACTIVE;
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/ClusterState.java b/persistence/src/main/java/com/yahoo/persistence/spi/ClusterState.java
deleted file mode 100644
index dbf7a90f49c..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/ClusterState.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi;
-
-/**
- * Class that allows a provider to figure out if the node is currently up, the cluster is up and/or a
- * given bucket should be "ready" given the state.
- */
-public interface ClusterState {
- /**
- * Returns true if the system has been set up to have
- * "ready" nodes, and the given bucket is in the ideal state
- * for readiness.
- *
- * @param bucket The bucket to check.
- * @return Returns true if the bucket should be set to "ready".
- */
- public boolean shouldBeReady(Bucket bucket);
-
- /**
- * @return Returns false if the cluster has been deemed down. This can happen
- * if the fleet controller has detected that too many nodes are down
- * compared to the complete list of nodes, and deigns the system to be
- * unusable.
- */
- public boolean clusterUp();
-
- /**
- * @return Returns false if this node has been set in a state where it should not
- * receive external load.
- */
- public boolean nodeUp();
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/ClusterStateImpl.java b/persistence/src/main/java/com/yahoo/persistence/spi/ClusterStateImpl.java
deleted file mode 100644
index 5d20f14dcc8..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/ClusterStateImpl.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi;
-
-import com.yahoo.vdslib.distribution.Distribution;
-import com.yahoo.vdslib.state.Node;
-import com.yahoo.vdslib.state.NodeType;
-
-import java.nio.ByteBuffer;
-import java.text.ParseException;
-
-/**
- * Implementation of the cluster state interface for deserialization from RPC.
- */
-public class ClusterStateImpl implements com.yahoo.persistence.spi.ClusterState {
- com.yahoo.vdslib.state.ClusterState clusterState;
- short clusterIndex;
- Distribution distribution;
-
- public ClusterStateImpl(byte[] serialized) throws ParseException {
- ByteBuffer buf = ByteBuffer.wrap(serialized);
-
- int clusterStateLength = buf.getInt();
- byte[] clusterState = new byte[clusterStateLength];
- buf.get(clusterState);
-
- clusterIndex = buf.getShort();
-
- int distributionLength = buf.getInt();
- byte[] distribution = new byte[distributionLength];
- buf.get(distribution);
-
- this.clusterState = new com.yahoo.vdslib.state.ClusterState(new String(clusterState));
- this.distribution = new Distribution("raw:" + new String(distribution));
- }
-
- @Override
- public boolean shouldBeReady(Bucket bucket) {
- return true;
- }
-
- @Override
- public boolean clusterUp() {
- return clusterState != null && clusterState.getClusterState().oneOf("u");
- }
-
- @Override
- public boolean nodeUp() {
- return !clusterUp() && clusterState.getNodeState(new Node(NodeType.STORAGE, clusterIndex)).getState().oneOf("uir");
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/DocEntry.java b/persistence/src/main/java/com/yahoo/persistence/spi/DocEntry.java
deleted file mode 100644
index 2217bbcb0f7..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/DocEntry.java
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi;
-
-import com.yahoo.document.Document;
-import com.yahoo.document.DocumentId;
-
-/**
- * Class that represents an entry retrieved by iterating.
- */
-public class DocEntry implements Comparable<DocEntry> {
-
-
- @Override
- public int compareTo(DocEntry docEntry) {
- return new Long(timestamp).compareTo(docEntry.getTimestamp());
- }
-
- public enum Type {
- PUT_ENTRY,
- REMOVE_ENTRY
- }
-
- long timestamp;
- Type type;
-
- DocumentId docId;
- Document document;
-
- public DocEntry(long timestamp, Document doc, Type type, DocumentId docId) {
- this.timestamp = timestamp;
- this.type = type;
- this.docId = docId;
- document = doc;
- }
-
-
- public DocEntry(long timestamp, Document doc) {
- this(timestamp, doc, Type.PUT_ENTRY, doc.getId());
- }
-
- public DocEntry(long timestamp, DocumentId docId) {
- this(timestamp, null, Type.REMOVE_ENTRY, docId);
- }
-
- public DocEntry(long timestamp, Type type) {
- this(timestamp, null, type, null);
- }
-
- public Type getType() { return type; }
-
- public long getTimestamp() { return timestamp; }
-
- public DocumentId getDocumentId() { return docId; }
-
- public Document getDocument() { return document; }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/PartitionState.java b/persistence/src/main/java/com/yahoo/persistence/spi/PartitionState.java
deleted file mode 100644
index b998989fce7..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/PartitionState.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi;
-
-/**
-* @author thomasg
-*/
-public class PartitionState {
- public PartitionState(State state, String reason) {
- this.state = state;
- this.reason = reason;
-
- if (reason == null || state == null) {
- throw new IllegalArgumentException("State and reason must be non-null");
- }
- }
-
- public State getState() { return state; }
- public String getReason() { return reason; }
-
- State state;
- String reason;
-
- public enum State {
- UP,
- DOWN
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/PersistenceProvider.java b/persistence/src/main/java/com/yahoo/persistence/spi/PersistenceProvider.java
deleted file mode 100644
index b33e631aadb..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/PersistenceProvider.java
+++ /dev/null
@@ -1,382 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi;
-
-import com.yahoo.document.Document;
-import com.yahoo.document.DocumentId;
-import com.yahoo.document.DocumentUpdate;
-import com.yahoo.document.fieldset.FieldSet;
-import com.yahoo.persistence.spi.result.*;
-
-/**
- * <p>
- * This interface is the basis for a persistence provider in Vespa.
- * A persistence provider is used by Vespa Storage to provide an elastic stateful system.
- * </p>
- * <p>
- * The Vespa distribution mechanisms are based on distributing "buckets"
- * between the nodes in the system. A bucket is an abstract concept that
- * groups a set of documents. The persistence provider can choose freely
- * how to implement a bucket, but it needs to be able to access a bucket as
- * a unit. The placement of these units is controlled by the distributors.
- * </p>
- * <p>
- * A persistence provider may support multiple "partitions". One example of
- * a partition is a physical disk, but the exact meaning of "partitions"
- * is left to the provider. It must be able to report to the service layer though.
- * </p>
- * <p>
- * All operations return a Result object. The base Result class only encapsulates
- * potential errors, which can be <i>transient</i>, <i>permanent</i> or <i>fatal</i>.
- * Transient errors are errors where it's conceivable that retrying the operation
- * would lead to success, either on this data copy or on others. Permanent errors
- * are errors where the request itself is faulty. Fatal errors are transient errors
- * that have uncovered a problem with this instance of the provider (such as a failing disk),
- * and where the provider wants the process to be shut down.
- * </p>
- * <p>
- * All write operations have a timestamp. This timestamp is generated
- * by the distributor, and is guaranteed to be unique for the bucket we're
- * writing to. A persistence provider is required to store "entries" for each of
- * these operations, and associate the timestamp with that entry.
- * Iteration code can retrieve these entries, including entries
- * for remove operations. The provider is not required to keep any history beyond
- * the last operation that was performed on a given document.
- * </p>
- * <p>
- * The contract for all write operations is that after returning from the function,
- * provider read methods (get, iterate) should reflect the modified state.
- * </p>
- */
-public interface PersistenceProvider
-{
- /**
- * The different types of entries that can be returned
- * from an iterator.
- */
- public enum IncludedVersions {
- NEWEST_DOCUMENT_ONLY,
- NEWEST_DOCUMENT_OR_REMOVE,
- ALL_VERSIONS
- }
-
- /**
- * The different kinds of maintenance we can do.
- * LOW maintenance may be run more often than HIGH.
- */
- public enum MaintenanceLevel {
- LOW,
- HIGH
- }
-
- /**
- * Initializes the persistence provider. This function is called exactly once when
- * the persistence provider starts. If any error is returned here, the service layer
- * will shut down.
- */
- Result initialize();
-
- /**
- * Returns a list of the partitions available,
- * and which are up and down.
- */
- PartitionStateListResult getPartitionStates();
-
- /**
- * Return list of buckets that provider has stored on the given partition.
- */
- BucketIdListResult listBuckets(short partition);
-
- /**
- * Updates the persistence provider with the last cluster state.
- * Only cluster states that are relevant for the provider are supplied (changes
- * that relate to the distributor will not cause an update here).
- */
- Result setClusterState(ClusterState state);
-
- /**
- * Sets the bucket state to active or inactive. After this returns,
- * other buckets may be deactivated, so the node must be able to serve
- * the data from its secondary index or get reduced coverage.
- */
- Result setActiveState(Bucket bucket, BucketInfo.ActiveState active);
-
- /**
- * If the bucket doesn't exist, return empty bucket info.
- */
- BucketInfoResult getBucketInfo(Bucket bucket);
-
- /**
- * Stores the given document.
- *
- * @param timestamp The timestamp for the new bucket entry.
- */
- Result put(Bucket bucket, long timestamp, Document doc);
-
- /**
- * <p>
- * Removes the document referenced by the document id.
- * It is strongly recommended to keep entries for the removes for
- * some period of time. For recovery to work properly, a node that
- * has been down for a longer period of time than that should be totally
- * erased. If not, documents that have been removed but have documents
- * on nodes that have been down will be reinserted.
- * </p>
- * <p>
- * Postconditions:
- * A successful invocation of this function must add the remove to the
- * bucket regardless of whether the document existed. More specifically,
- * iterating over the bucket while including removes after this call
- * shall yield a remove-entry at the given timestamp for the given
- * document identifier as part of its result set. The remove entry
- * shall be added even if there exist removes for the same document id
- * at other timestamps in the bucket.
- * </p>
- * <p>
- * Also, if the given timestamp is higher to or equal than any
- * existing put entry, those entries should not be returned in subsequent
- * get calls. If the timestamp is lower than an existing put entry,
- * those entries should still be available.
- * </p>
- * @param timestamp The timestamp for the new bucket entry.
- * @param id The ID to remove
- */
- RemoveResult remove(Bucket bucket, long timestamp, DocumentId id);
- /**
- * <p>
- * See remove()
- * </p>
- * <p>
- * Used for external remove operations. removeIfFound() has no extra
- * postconditions than remove, but it may choose to <i>not</i> include
- * a remove entry if there didn't already exist a put entry for the given
- * entry. It is recommended, but not required, to not insert entries in this
- * case, though if remove entries are considered critical it might be better
- * to insert them in both cases.
- * </p>
- * @param timestamp The timestamp for the new bucket entry.
- * @param id The ID to remove
- */
- RemoveResult removeIfFound(Bucket bucket, long timestamp, DocumentId id);
-
- /**
- * Removes the entry with the given timestamp. This is usually used to revert
- * previously performed operations. This operation should be
- * successful even if there doesn't exist such an entry.
- */
- Result removeEntry(Bucket bucket, long timestampToRemove);
-
- /**
- * Partially modifies a document referenced by the document update.
- *
- * @param timestamp The timestamp to use for the new update entry.
- * @param update The document update to apply to the stored document.
- */
- UpdateResult update(Bucket bucket, long timestamp, DocumentUpdate update);
-
- /**
- * <p>
- * For providers that store data persistently on disk, the contract of
- * flush is that data has been stored persistently so that if the node should
- * restart, the data will be available.
- * </p>
- * <p>
- * The service layer may choose to batch certain commands. This means
- * that the service layer will lock the bucket only once, then perform several
- * commands, and finally get the bucket info from the bucket, and then flush it.
- * This can be used to improve performance by caching the modifications, and
- * persisting them to disk only when flush is called. The service layer guarantees
- * that after one of these operations, flush() is called, regardless of whether
- * the operation succeeded or not, before another bucket is processed in the same
- * worker thread. The following operations can be batched and have the guarantees
- * above:
- * - put
- * - get
- * - remove
- * - removeIfFound
- * - update
- * - removeEntry
- * </p>
- */
- Result flush(Bucket bucket);
-
- /**
- * Retrieves the latest version of the document specified by the
- * document id. If no versions were found, or the document was removed,
- * the result should be successful, but contain no document (see GetResult).
- *
- * @param fieldSet A set of fields that should be retrieved.
- * @param id The document id to retrieve.
- */
- GetResult get(Bucket bucket, FieldSet fieldSet, DocumentId id);
-
- /**
- * Create an iterator for a given bucket and selection criteria, returning
- * a unique, non-zero iterator identifier that can be used by the caller as
- * an argument to iterate and destroyIterator.
- *
- * Each successful invocation of createIterator shall be paired with
- * a later invocation of destroyIterator by the caller to ensure
- * resources are freed up. NOTE: this may not apply in a shutdown
- * situation due to service layer communication channels closing down.
- *
- * It is assumed that a successful invocation of this function will result
- * in some state being established in the persistence provider, holding
- * the information required to match iterator ids up to their current
- * iteration progress and selection criteria. destroyIterator will NOT
- * be called when createIterator returns an error.
- *
- * @param selection Selection criteria used to limit the subset of
- * the bucket's documents that will be returned by the iterator. The
- * provider implementation may use these criteria to optimize its
- * operation as it sees fit, as long as doing so does not violate
- * selection correctness.
- * @return A process-globally unique iterator identifier iff the result
- * is successful and internal state has been created, otherwise an
- * error. Identifier must be non-zero, as zero is used internally to
- * signify an invalid iterator ID.
- */
- CreateIteratorResult createIterator(Bucket bucket,
- FieldSet fieldSet,
- Selection selection,
- IncludedVersions versions);
-
- /**
- * Iterate over a bucket's document space using a valid iterator id
- * received from createIterator. Each invocation of iterate upon an
- * iterator that has not yet fully exhausted its document space shall
- * return a minimum of 1 document entry per IterateResult to ensure progress.
- * An implementation shall limit the result set per invocation to document
- * entries whose combined in-memory/serialized size is a "soft" maximum of
- * maxByteSize. More specifically, the sum of getSize() over all returned
- * DocEntry instances should be &lt;= (maxByteSize + the size of the last
- * document in the result set). This special case allows for limiting the
- * result set both by observing "before the fact" that the next potential
- * document to include would exceed the max size and by observing "after
- * the fact" that the document that was just added caused the max size to
- * be exceeded.
- * However, if a document exceeds maxByteSize and not including it implies
- * the result set would be empty, it must be included in the result anyway
- * in order to not violate the progress requirement.
- *
- * The caller shall not make any assumptions on whether or not documents
- * that arrive to--or are removed from--the bucket in the time between
- * separate invocations of iterate for the same iterator id will show up
- * in the results, assuming that these documents do not violate the
- * selection criteria. This means that there is no requirement for
- * maintaining a "snapshot" view of the bucket's state as it existed upon
- * the initial createIterator call. Neither shall the caller make any
- * assumptions on the ordering of the returned documents.
- *
- * The IterateResult shall--for each document entry that matches the
- * selection criteria and falls within the maxByteSize limit mentioned
- * above--return the following information in its result:
- *
- * -- For non-removed entries: A DocEntry where getDocumentOperation() will
- * return a valid DocumentPut instance and getSize() will return the
- * serialized size of the document.
- * -- For removed entries: A DocEntry where getDocumentId() will
- * return a valid document identifier. Remove entries shall not
- * contain document instances.
- * -- For meta entries: A DocEntry that shall not contain a document
- * instance nor should it include a document id instance (if
- * included, would be ignored by the service layer in any context
- * where metadata-only is requested).
- *
- * The service layer shall guarantee that no two invocations of iterate
- * will happen simultaneously/concurrently for the same iterator id.
- *
- * Upon a successful invocation of iterate, the persistence provider shall
- * update its internal state to account for the progress made so that new
- * invocations will cover a new subset of the document space. When an
- * IterateResult contains the final documents for the iteration, i.e. the
- * iterator has reached its end, setCompleted() must be set on the result
- * to indicate this to the caller. Calling iterate on an already completed
- * iterator must only set this flag on the result and return without any
- * documents.
- *
- * @param iteratorId An iterator ID returned by a previous call to createIterator
- * @param maxByteSize An indication of the maximum number of bytes that should be returned.
- */
- IterateResult iterate(long iteratorId, long maxByteSize);
-
- /**
- * <p>
- * Destroys the iterator specified by the given id.
- * </p>
- * <p>
- * IMPORTANT: this method has different invocation semantics than
- * the other provider methods! It may be called from the context of
- * ANY service layer thread, NOT just from the thread in which
- * createIterator was invoked! The reason for this is because internal
- * iterator destroy messages aren't mapped to partition threads in the
- * way other messages are due to their need for guaranteed execution.
- * </p>
- * <p>
- * This in turn implies that iterator states must be shared between
- * partitions (and thus protected against cross-partition concurrent
- * access).
- * </p>
- * @param iteratorId The iterator id previously returned by createIterator.
- */
- Result destroyIterator(long iteratorId);
-
- /**
- * Tells the provider that the given bucket has been created in the
- * service layer. There is no requirement to do anything here.
- */
- Result createBucket(Bucket bucket);
-
- /**
- * Deletes the given bucket and all entries contained in that bucket.
- * After this operation has succeeded, a restart of the provider should
- * not yield the bucket in getBucketList().
- */
- Result deleteBucket(Bucket bucket);
-
- /**
- * This function is called continuously by the service layer. It allows
- * the provider to signify whether it has done any out-of-band changes to
- * buckets that need to be recognized by the rest of the system. The service
- * layer will proceed to call getBucketInfo() on each of the returned buckets.
- * After a call to getModifiedBuckets(), the provider should clear it's list
- * of modified buckets, so that the next call does not return the same buckets.
- */
- BucketIdListResult getModifiedBuckets();
-
- /**
- * Allows the provider to do periodic maintenance and verification.
- *
- * @param level The level of maintenance to do. LOW maintenance is scheduled more
- * often than HIGH maintenance, so should be cheaper.
- */
- Result maintain(Bucket bucket, MaintenanceLevel level);
-
- /**
- * <p>
- * Splits the source bucket into the two target buckets.
- * After the split, all documents belonging to target1 should be
- * in that bucket, and all documents belonging to target2 should be
- * there. The information in SplitResult should reflect
- * this.
- * </p>
- * <p>
- * Before calling this function, the service layer will iterate the bucket
- * to figure out which buckets the source should be split into. This may
- * result in splitting more than one bucket bit at a time.
- * </p>
- */
- Result split(Bucket source, Bucket target1, Bucket target2);
-
- /**
- * Joins two buckets into one. After the join, all documents from
- * source1 and source2 should be stored in the target bucket.
- */
- Result join(Bucket source1, Bucket source2, Bucket target);
-
- /**
- * Moves a bucket from one partition to another.
- *
- * @param partitionId The partition to move to.
- */
- Result move(Bucket bucket, short partitionId);
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/Selection.java b/persistence/src/main/java/com/yahoo/persistence/spi/Selection.java
deleted file mode 100644
index 4bcf75fa322..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/Selection.java
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi;
-
-import com.yahoo.document.Document;
-import com.yahoo.document.DocumentPut;
-import com.yahoo.document.select.DocumentSelector;
-import com.yahoo.document.select.Result;
-import com.yahoo.document.select.parser.ParseException;
-
-import java.util.Set;
-
-/**
- * Class used when iterating to represent a selection of entries to be returned.
- *
- * This class is likely to be replaced by a more generic selection AST in the near future.
- */
-public class Selection {
- DocumentSelector documentSelection = null;
- long fromTimestamp = 0;
- long toTimestamp = Long.MAX_VALUE;
- Set<Long> timestampSubset = null;
-
- public Selection(String documentSelection, long fromTimestamp, long toTimestamp) throws ParseException {
- this.documentSelection = new DocumentSelector(documentSelection);
- this.fromTimestamp = fromTimestamp;
- this.toTimestamp = toTimestamp;
- }
-
- public Selection(Set<Long> timestampSubset) {
- this.timestampSubset = timestampSubset;
- }
-
- public boolean requiresFields() {
- return documentSelection != null;
- }
-
- public Set<Long> getTimestampSubset() {
- return timestampSubset;
- }
-
- /**
- * Returns true if the entry matches the selection criteria given.
- */
- public boolean match(Document doc, long timestamp) {
- if (timestamp < fromTimestamp) {
- return false;
- }
-
- if (timestamp > toTimestamp) {
- return false;
- }
-
- if (timestampSubset != null && !timestampSubset.contains(timestamp)) {
- return false;
- }
-
- if (documentSelection != null && doc != null && !documentSelection.accepts(new DocumentPut(doc)).equals(Result.TRUE)) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Returns true if the entry matches the timestamp ranges/subsets specified in the selection.
- */
- public boolean match(long timestamp) {
- return match(null, timestamp);
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/conformance/ConformanceTest.java b/persistence/src/main/java/com/yahoo/persistence/spi/conformance/ConformanceTest.java
deleted file mode 100644
index f3e7166b078..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/conformance/ConformanceTest.java
+++ /dev/null
@@ -1,1605 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi.conformance;
-
-import com.yahoo.document.BucketId;
-import com.yahoo.document.*;
-import com.yahoo.document.datatypes.IntegerFieldValue;
-import com.yahoo.document.datatypes.StringFieldValue;
-import com.yahoo.document.fieldset.AllFields;
-import com.yahoo.document.fieldset.FieldSet;
-import com.yahoo.document.update.AssignValueUpdate;
-import com.yahoo.document.update.FieldUpdate;
-import com.yahoo.persistence.spi.*;
-import com.yahoo.persistence.spi.result.*;
-import junit.framework.TestCase;
-
-import java.util.*;
-
-public abstract class ConformanceTest extends TestCase {
- TestDocMan testDocMan = new TestDocMan();
-
- public interface PersistenceProviderFactory {
- public PersistenceProvider createProvider(DocumentTypeManager manager);
- public boolean supportsActiveState();
- }
-
- PersistenceProvider init(PersistenceProviderFactory factory) {
- return factory.createProvider(testDocMan);
- }
-
- // TODO: should invoke some form of destruction method on the provider after a test
- protected void doConformanceTest(PersistenceProviderFactory factory) throws Exception {
- testBasics(init(factory));
- testPut(init(factory));
- testRemove(init(factory));
- testGet(init(factory));
- testUpdate(init(factory));
-
- testListBuckets(init(factory));
- testBucketInfo(init(factory));
- testOrderIndependentBucketInfo(init(factory));
- testPutNewDocumentVersion(init(factory));
- testPutOlderDocumentVersion(init(factory));
- testPutDuplicate(init(factory));
- testDeleteBucket(init(factory));
- testSplitNormalCase(init(factory));
- testSplitTargetExists(init(factory));
- testJoinNormalCase(init(factory));
- testJoinTargetExists(init(factory));
- testJoinOneBucket(init(factory));
-
- testMaintain(init(factory));
- testGetModifiedBuckets(init(factory));
-
- if (factory.supportsActiveState()) {
- testBucketActivation(init(factory));
- testBucketActivationSplitAndJoin(init(factory));
- }
-
- testIterateAllDocs(init(factory));
- testIterateAllDocsNewestVersionOnly(init(factory));
- testIterateCreateIterator(init(factory));
- testIterateDestroyIterator(init(factory));
- testIterateWithUnknownId(init(factory));
- testIterateChunked(init(factory));
- testIterateMatchTimestampRange(init(factory));
- testIterateMaxByteSize(init(factory));
- testIterateExplicitTimestampSubset(init(factory));
- testIterateMatchSelection(init(factory));
- testIterateRemoves(init(factory));
- testIterationRequiringDocumentIdOnlyMatching(init(factory));
- testIterateAlreadyCompleted(init(factory));
- testIterateEmptyBucket(init(factory));
-
- testRemoveMerge(init(factory));
- }
-
- List<DocEntry> iterateBucket(PersistenceProvider spi, Bucket bucket, PersistenceProvider.IncludedVersions versions) throws Exception {
- List<DocEntry> ret = new ArrayList<DocEntry>();
-
- CreateIteratorResult iter = spi.createIterator(
- bucket,
- new AllFields(),
- new Selection("", 0, Long.MAX_VALUE),
- versions);
-
- assertFalse(iter.hasError());
-
- while (true) {
- IterateResult result = spi.iterate(iter.getIteratorId(), Long.MAX_VALUE);
- assertFalse(result.hasError());
-
- ret.addAll(result.getEntries());
-
- if (result.isCompleted()) {
- break;
- }
- }
-
- Collections.sort(ret);
-
- return ret;
- }
-
- void testBasicsIteration(PersistenceProvider provider, Bucket bucket, Document doc1, Document doc2, boolean includeRemoves) throws Exception {
- Selection selection = new Selection("true", 0, Long.MAX_VALUE);
-
- CreateIteratorResult iter = provider.createIterator(
- bucket,
- new AllFields(),
- selection,
- includeRemoves ? PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_OR_REMOVE : PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY);
-
- assertTrue(!iter.hasError());
-
- IterateResult result = provider.iterate(iter.getIteratorId(), Long.MAX_VALUE);
- assertTrue(!result.hasError());
- assertTrue(result.isCompleted());
- assertEquals(new Result(), provider.destroyIterator(iter.getIteratorId()));
-
- long timeRemoveDoc1 = 0;
- long timeDoc1 = 0;
- long timeDoc2 = 0;
-
- for (DocEntry entry : result.getEntries()) {
- assertNotNull(entry.getDocumentId());
-
- if (entry.getDocumentId().equals(doc1.getId())) {
- assertTrue("Got removed document 1 when iterating without removes", includeRemoves);
-
- if (entry.getType() == DocEntry.Type.REMOVE_ENTRY) {
- timeRemoveDoc1 = entry.getTimestamp();
- } else {
- timeDoc1 = entry.getTimestamp();
- }
- } else if (entry.getDocumentId().equals(doc2.getId())) {
- assertEquals(DocEntry.Type.PUT_ENTRY, entry.getType());
- timeDoc2 = entry.getTimestamp();
- } else {
- assertFalse("Unknown document " + entry.getDocumentId(), false);
- }
- }
-
- assertEquals(2, timeDoc2);
- assertTrue(timeDoc1 == 0 || timeRemoveDoc1 != 0);
- }
-
- void testBasics(PersistenceProvider provider) throws Exception {
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
- Document doc2 = testDocMan.createRandomDocumentAtLocation(0x01, 2);
-
- assertEquals(new Result(), provider.createBucket(bucket));
- assertEquals(new Result(), provider.put(bucket, 1, doc1));
- assertEquals(new Result(), provider.put(bucket, 2, doc2));
-
- assertEquals(new RemoveResult(true), provider.remove(bucket, 3, doc1.getId()));
- assertEquals(new Result(), provider.flush(bucket));
-
- testBasicsIteration(provider, bucket, doc1, doc2, false);
- testBasicsIteration(provider, bucket, doc1, doc2, true);
- }
-
- void testListBuckets(PersistenceProvider provider) {
- BucketId bucketId1 = new BucketId(8, 0x01);
- BucketId bucketId2 = new BucketId(8, 0x02);
- BucketId bucketId3 = new BucketId(8, 0x03);
-
- Bucket bucket1 = new Bucket((short)0, bucketId1);
- Bucket bucket2 = new Bucket((short)0, bucketId2);
- Bucket bucket3 = new Bucket((short)0, bucketId3);
-
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
- Document doc2 = testDocMan.createRandomDocumentAtLocation(0x02, 2);
- Document doc3 = testDocMan.createRandomDocumentAtLocation(0x03, 3);
-
- provider.createBucket(bucket1);
- provider.createBucket(bucket2);
- provider.createBucket(bucket3);
-
- provider.put(bucket1, 1, doc1);
- provider.flush(bucket1);
-
- provider.put(bucket2, 2, doc2);
- provider.flush(bucket2);
-
- provider.put(bucket3, 3, doc3);
- provider.flush(bucket3);
-
- BucketIdListResult result = provider.listBuckets((short)0);
- assertEquals(3, result.getBuckets().size());
- assertTrue(result.getBuckets().contains(bucketId1));
- assertTrue(result.getBuckets().contains(bucketId2));
- assertTrue(result.getBuckets().contains(bucketId3));
- }
-
- void testBucketInfo(PersistenceProvider provider) {
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
-
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
- Document doc2 = testDocMan.createRandomDocumentAtLocation(0x01, 2);
-
- provider.createBucket(bucket);
- provider.put(bucket, 2, doc2);
-
- BucketInfo info = provider.getBucketInfo(bucket).getBucketInfo();
- provider.flush(bucket);
-
- assertEquals(1, info.getDocumentCount());
- assertTrue(info.getChecksum() != 0);
-
- provider.put(bucket, 3, doc1);
- BucketInfo info2 = provider.getBucketInfo(bucket).getBucketInfo();
- provider.flush(bucket);
-
- assertEquals(2, info2.getDocumentCount());
- assertTrue(info2.getChecksum() != 0);
- assertTrue(info.getChecksum() != info2.getChecksum());
-
- provider.put(bucket, 4, doc1);
- BucketInfo info3 = provider.getBucketInfo(bucket).getBucketInfo();
- provider.flush(bucket);
-
- assertEquals(2, info3.getDocumentCount());
- assertTrue(info3.getChecksum() != 0);
- assertTrue(info2.getChecksum() != info3.getChecksum());
-
- provider.remove(bucket, 5, doc1.getId());
- BucketInfo info4 = provider.getBucketInfo(bucket).getBucketInfo();
- provider.flush(bucket);
-
- assertEquals(1, info4.getDocumentCount());
- assertTrue(info4.getChecksum() != 0);
- }
-
-
- void testOrderIndependentBucketInfo(PersistenceProvider spi)
- {
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
-
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
- Document doc2 = testDocMan.createRandomDocumentAtLocation(0x01, 2);
- spi.createBucket(bucket);
-
- int checksumOrdered = 0;
-
- {
- spi.put(bucket, 2, doc1);
- spi.put(bucket, 3, doc2);
- spi.flush(bucket);
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
-
- checksumOrdered = info.getChecksum();
- assertTrue(checksumOrdered != 0);
- }
-
- spi.deleteBucket(bucket);
- spi.createBucket(bucket);
- assertEquals(0, spi.getBucketInfo(bucket).getBucketInfo().getChecksum());
-
- int checksumUnordered = 0;
-
- {
- // Swap order of puts
- spi.put(bucket, 3, doc2);
- spi.put(bucket, 2, doc1);
- spi.flush(bucket);
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
-
- checksumUnordered = info.getChecksum();
- assertTrue(checksumUnordered != 0);
- }
-
- assertEquals(checksumOrdered, checksumUnordered);
- }
-
- void testPut(PersistenceProvider spi) {
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
-
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
- spi.createBucket(bucket);
-
- assertEquals(new Result(), spi.put(bucket, 3, doc1));
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
- spi.flush(bucket);
-
- assertEquals(1, (int)info.getDocumentCount());
- assertTrue(info.getEntryCount() >= info.getDocumentCount());
- assertTrue(info.getChecksum() != 0);
- assertTrue(info.getDocumentSize() > 0);
- assertTrue(info.getUsedSize() >= info.getDocumentSize());
- }
-
- void testPutNewDocumentVersion(PersistenceProvider spi) {
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
-
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
- Document doc2 = doc1.clone();
-
-
- doc2.setFieldValue("content", new StringFieldValue("hiho silver"));
- spi.createBucket(bucket);
-
- Result result = spi.put(bucket, 3, doc1);
- {
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
- spi.flush(bucket);
-
- assertEquals(1, (int)info.getDocumentCount());
- assertTrue(info.getEntryCount() >= info.getDocumentCount());
- assertTrue(info.getChecksum() != 0);
- assertTrue(info.getDocumentSize() > 0);
- assertTrue(info.getUsedSize() >= info.getDocumentSize());
- }
-
- result = spi.put(bucket, 4, doc2);
- {
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
- spi.flush(bucket);
-
- assertEquals(1, (int)info.getDocumentCount());
- assertTrue(info.getEntryCount() >= info.getDocumentCount());
- assertTrue(info.getChecksum() != 0);
- assertTrue(info.getDocumentSize() > 0);
- assertTrue(info.getUsedSize() >= info.getDocumentSize());
- }
-
- GetResult gr = spi.get(bucket, new AllFields(), doc1.getId());
-
- assertEquals(Result.ErrorType.NONE, gr.getErrorType());
- assertEquals(4, gr.getLastModifiedTimestamp());
- assertEquals(doc2, gr.getDocument());
- }
-
- void testPutOlderDocumentVersion(PersistenceProvider spi) {
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
-
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
- Document doc2 = doc1.clone();
- doc2.setFieldValue("content", new StringFieldValue("hiho silver"));
- spi.createBucket(bucket);
-
- Result result = spi.put(bucket, 5, doc1);
- BucketInfo info1 = spi.getBucketInfo(bucket).getBucketInfo();
- spi.flush(bucket);
- {
- assertEquals(1, info1.getDocumentCount());
- assertTrue(info1.getEntryCount() >= info1.getDocumentCount());
- assertTrue(info1.getChecksum() != 0);
- assertTrue(info1.getDocumentSize() > 0);
- assertTrue(info1.getUsedSize() >= info1.getDocumentSize());
- }
-
- result = spi.put(bucket, 4, doc2);
- {
- BucketInfo info2 = spi.getBucketInfo(bucket).getBucketInfo();
- spi.flush(bucket);
-
- assertEquals(1, info2.getDocumentCount());
- assertTrue(info2.getEntryCount() >= info1.getDocumentCount());
- assertEquals(info1.getChecksum(), info2.getChecksum());
- assertEquals(info1.getDocumentSize(), info2.getDocumentSize());
- assertTrue(info2.getUsedSize() >= info1.getDocumentSize());
- }
-
- GetResult gr = spi.get(bucket, new AllFields(), doc1.getId());
-
- assertEquals(Result.ErrorType.NONE, gr.getErrorType());
- assertEquals(5, gr.getLastModifiedTimestamp());
- assertEquals(doc1, gr.getDocument());
- }
-
- void testPutDuplicate(PersistenceProvider spi) throws Exception {
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
-
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
- spi.createBucket(bucket);
- assertEquals(new Result(), spi.put(bucket, 3, doc1));
-
- int checksum;
- {
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
- spi.flush(bucket);
- assertEquals(1, (int)info.getDocumentCount());
- checksum = info.getChecksum();
- }
- assertEquals(new Result(), spi.put(bucket, 3, doc1));
-
- {
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
- spi.flush(bucket);
- assertEquals(1, (int)info.getDocumentCount());
- assertEquals(checksum, info.getChecksum());
- }
-
- List<DocEntry> entries = iterateBucket(spi, bucket, PersistenceProvider.IncludedVersions.ALL_VERSIONS);
- assertEquals(1, entries.size());
- }
-
-
- void testRemove(PersistenceProvider spi) throws Exception {
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
-
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
- spi.createBucket(bucket);
-
- Result result = spi.put(bucket, 3, doc1);
-
- {
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
- spi.flush(bucket);
-
- assertEquals(1, (int)info.getDocumentCount());
- assertTrue(info.getChecksum() != 0);
-
- List<DocEntry> entries = iterateBucket(spi, bucket, PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY);
- assertEquals(1, entries.size());
- }
-
- RemoveResult result2 = spi.removeIfFound(bucket, 5, doc1.getId());
-
- {
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
- spi.flush(bucket);
-
- assertEquals(0, info.getDocumentCount());
- assertEquals(0, info.getChecksum());
- assertEquals(true, result2.wasFound());
- }
-
- assertEquals(0, iterateBucket(spi, bucket, PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY).size());
- assertEquals(1, iterateBucket(spi, bucket, PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_OR_REMOVE).size());
-
- RemoveResult result3 = spi.remove(bucket, 7, doc1.getId());
-
- {
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
- spi.flush(bucket);
-
- assertEquals(0, (int)info.getDocumentCount());
- assertEquals(0, (int)info.getChecksum());
- assertEquals(false, result3.wasFound());
- }
-
- Result result4 = spi.put(bucket, 9, doc1);
- spi.flush(bucket);
-
- assertTrue(!result4.hasError());
-
- RemoveResult result5 = spi.remove(bucket, 9, doc1.getId());
-
- {
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
- spi.flush(bucket);
-
- assertEquals(0, (int)info.getDocumentCount());
- assertEquals(0, (int)info.getChecksum());
- assertEquals(true, result5.wasFound());
- assertTrue(!result5.hasError());
- }
-
- GetResult getResult = spi.get(bucket, new AllFields(), doc1.getId());
- assertEquals(Result.ErrorType.NONE, getResult.getErrorType());
- assertEquals(0, getResult.getLastModifiedTimestamp());
- assertNull(getResult.getDocument());
- }
-
- void testRemoveMerge(PersistenceProvider spi) throws Exception {
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
-
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
- DocumentId removeId = new DocumentId("userdoc:fraggle:1:rock");
- spi.createBucket(bucket);
-
- Result result = spi.put(bucket, 3, doc1);
-
- // Remove a document that does not exist
- {
- RemoveResult removeResult = spi.remove(bucket, 10, removeId);
- spi.flush(bucket);
- assertEquals(Result.ErrorType.NONE, removeResult.getErrorType());
- assertEquals(false, removeResult.wasFound());
- }
- // In a merge case, there might be multiple removes for the same document
- // if resending et al has taken place. These must all be added.
- {
- RemoveResult removeResult = spi.remove(bucket,
- 5,
- removeId);
- spi.flush(bucket);
- assertEquals(Result.ErrorType.NONE, removeResult.getErrorType());
- assertEquals(false, removeResult.wasFound());
- }
- {
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
-
- assertEquals(1, info.getDocumentCount());
- assertEquals(3, info.getEntryCount());
- assertTrue(info.getChecksum() != 0);
- }
- assertFalse(spi.flush(bucket).hasError());
-
- List<DocEntry> entries = iterateBucket(spi, bucket, PersistenceProvider.IncludedVersions.ALL_VERSIONS);
- // Remove entries should exist afterwards
- assertEquals(3, entries.size());
- for (int i = 2; i > 0; --i) {
- assertEquals((i == 2) ? 10 : 5, entries.get(i).getTimestamp());
- assertTrue(entries.get(i).getType() == DocEntry.Type.REMOVE_ENTRY);
- assertNotNull(entries.get(i).getDocumentId());
- assertEquals(removeId, entries.get(i).getDocumentId());
- }
-
- // Result tagged as document not found if CONVERT_PUT_TO_REMOVE flag is given and
- // timestamp does not exist, and PERSIST_NONEXISTING is not set
-
- // CONVERTED_REMOVE flag should be set if CONVERT_PUT_TO_REMOVE is set.
-
- // Trying to turn a remove without CONVERTED_REMOVE flag set into
- // unrevertable remove should work. (Should likely log warning, but we want
- // to do it anyways, in order to get bucket copies in sync if it happens)
-
- // Timestamps should not have been changed.
-
- // Verify that a valid and altered bucket info is returned on success
- }
-
- void testUpdate(PersistenceProvider spi) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
- spi.createBucket(bucket);
-
- DocumentType docType = testDocMan.getDocumentType("testdoctype1");
-
- DocumentUpdate update = new DocumentUpdate(docType, doc1.getId());
- FieldUpdate fieldUpdate = FieldUpdate.create(docType.getField("headerval"));
- fieldUpdate.addValueUpdate(AssignValueUpdate.createAssign(new IntegerFieldValue(42)));
- update.addFieldUpdate(fieldUpdate);
-
- {
- UpdateResult result = spi.update(bucket, 3, update);
- spi.flush(bucket);
- assertEquals(Result.ErrorType.NONE, result.getErrorType());
- assertEquals(0, result.getExistingTimestamp());
- }
-
- spi.put(bucket, 3, doc1);
- {
- UpdateResult result = spi.update(bucket, 4, update);
- spi.flush(bucket);
-
- assertEquals(Result.ErrorType.NONE, result.getErrorType());
- assertEquals(3, result.getExistingTimestamp());
- }
-
- {
- GetResult result = spi.get(bucket, new AllFields(), doc1.getId());
-
- assertEquals(Result.ErrorType.NONE, result.getErrorType());
- assertEquals(4, result.getLastModifiedTimestamp());
- assertEquals(new IntegerFieldValue(42), result.getDocument().getFieldValue("headerval"));
- }
-
- spi.remove(bucket, 5, doc1.getId());
- spi.flush(bucket);
-
- {
- GetResult result = spi.get(bucket, new AllFields(), doc1.getId());
-
- assertEquals(Result.ErrorType.NONE, result.getErrorType());
- assertEquals(0, result.getLastModifiedTimestamp());
- assertNull(result.getDocument());
- }
-
-
- {
- UpdateResult result = spi.update(bucket, 6, update);
- spi.flush(bucket);
-
- assertEquals(Result.ErrorType.NONE, result.getErrorType());
- assertEquals(0, result.getExistingTimestamp());
- }
- }
-
- void testGet(PersistenceProvider spi) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
-
- spi.createBucket(bucket);
-
- {
- GetResult result = spi.get(bucket, new AllFields(), doc1.getId());
-
- assertEquals(Result.ErrorType.NONE, result.getErrorType());
- assertEquals(0, result.getLastModifiedTimestamp());
- }
-
- spi.put(bucket, 3, doc1);
- spi.flush(bucket);
-
- {
- GetResult result = spi.get(bucket, new AllFields(), doc1.getId());
- assertEquals(doc1, result.getDocument());
- assertEquals(3, result.getLastModifiedTimestamp());
- }
-
- spi.remove(bucket,
- 4,
- doc1.getId());
- spi.flush(bucket);
-
- {
- GetResult result = spi.get(bucket, new AllFields(), doc1.getId());
-
- assertEquals(Result.ErrorType.NONE, result.getErrorType());
- assertEquals(0, result.getLastModifiedTimestamp());
- }
- }
-
- void
- testIterateCreateIterator(PersistenceProvider spi) throws Exception
- {
-
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
-
- spi.createBucket(bucket);
-
- CreateIteratorResult result = spi.createIterator(bucket, new AllFields(), new Selection("", 0, Long.MAX_VALUE), PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY);
- assertEquals(Result.ErrorType.NONE, result.getErrorType());
- // Iterator ID 0 means invalid iterator, so cannot be returned
- // from a successful createIterator call.
- assertTrue(result.getIteratorId() != 0);
-
- spi.destroyIterator(result.getIteratorId());
- }
-
- void
- testIterateDestroyIterator(PersistenceProvider spi) throws Exception
- {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
-
- CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("", 0, Long.MAX_VALUE), PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY);
-
- {
- IterateResult result = spi.iterate(iter.getIteratorId(), 1024);
- assertEquals(Result.ErrorType.NONE, result.getErrorType());
- }
-
- {
- Result destroyResult = spi.destroyIterator(iter.getIteratorId());
- assertTrue(!destroyResult.hasError());
- }
- // Iteration should now fail
- {
- IterateResult result = spi.iterate(iter.getIteratorId(), 1024);
- assertEquals(Result.ErrorType.PERMANENT_ERROR, result.getErrorType());
- }
- {
- Result destroyResult = spi.destroyIterator(iter.getIteratorId());
- assertTrue(!destroyResult.hasError());
- }
- }
-
- List<DocEntry> feedDocs(PersistenceProvider spi, Bucket bucket,
- int numDocs,
- int minSize,
- int maxSize)
- {
- List<DocEntry> docs = new ArrayList<DocEntry>();
-
- for (int i = 0; i < numDocs; ++i) {
- Document doc = testDocMan.createRandomDocumentAtLocation(
- bucket.getBucketId().getId(),
- i,
- minSize,
- maxSize);
- Result result = spi.put(bucket, 1000 + i, doc);
- assertTrue(!result.hasError());
- docs.add(new DocEntry(1000 + i, doc));
- }
- assertEquals(new Result(), spi.flush(bucket));
- return docs;
- }
-
- void
- testIterateWithUnknownId(PersistenceProvider spi)
- {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
-
- IterateResult result = spi.iterate(123, 1024);
- assertEquals(Result.ErrorType.PERMANENT_ERROR, result.getErrorType());
- }
-
- /**
- * Do a full bucket iteration, returning a vector of DocEntry chunks.
- */
- List<IterateResult> doIterate(PersistenceProvider spi,
- long id,
- long maxByteSize,
- int maxChunks)
- {
- List<IterateResult> chunks = new ArrayList<IterateResult>();
-
- while (true) {
- IterateResult result = spi.iterate(id, maxByteSize);
- assertFalse(result.hasError());
-
- assertTrue(result.getEntries().size() > 0);
- chunks.add(result);
-
- if (result.isCompleted()
- || (maxChunks != 0 && chunks.size() >= maxChunks))
- {
- break;
- }
- }
- return chunks;
- }
-
- boolean containsDocument(List<IterateResult> chunks, Document doc) {
- for (IterateResult i : chunks) {
- for (DocEntry e : i.getEntries()) {
- if (e.getType() == DocEntry.Type.PUT_ENTRY && e.getDocument() != null && e.getDocument().equals(doc)) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- boolean containsRemove(List<IterateResult> chunks, String docId) {
- for (IterateResult i : chunks) {
- for (DocEntry e : i.getEntries()) {
- if (e.getType() == DocEntry.Type.REMOVE_ENTRY && e.getDocumentId() != null && e.getDocumentId().toString().equals(docId)) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- void verifyDocs(List<DocEntry> docs, List<IterateResult> chunks, List<String> removes) {
- int docCount = 0;
- int removeCount = 0;
- for (IterateResult result : chunks) {
- for (DocEntry e : result.getEntries()) {
- if (e.getType() == DocEntry.Type.PUT_ENTRY) {
- ++docCount;
- } else {
- ++removeCount;
- }
- }
- }
-
- assertEquals(docs.size(), docCount);
-
- for (DocEntry e : docs) {
- assertTrue(e.getDocument().toString(), containsDocument(chunks, e.getDocument()));
- }
-
- if (removes != null) {
- assertEquals(removes.size(), removeCount);
-
- for (String docId : removes) {
- assertTrue(docId, containsRemove(chunks, docId));
- }
- }
- }
-
- void verifyDocs(List<DocEntry> docs, List<IterateResult> chunks) {
- verifyDocs(docs, chunks, null);
- }
-
-
- void testIterateAllDocs(PersistenceProvider spi) throws Exception {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
-
- List<DocEntry> docs = feedDocs(spi, b, 100, 110, 110);
-
- CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("", 0, Long.MAX_VALUE), PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY);
-
- List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 4096, 0);
- verifyDocs(docs, chunks);
-
- spi.destroyIterator(iter.getIteratorId());
- }
-
- void testIterateAllDocsNewestVersionOnly(PersistenceProvider spi) throws Exception {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
-
- List<DocEntry> docs = feedDocs(spi, b, 100, 110, 110);
- List<DocEntry> newDocs = new ArrayList<DocEntry>();
-
- for (DocEntry e : docs) {
- Document newDoc = e.getDocument().clone();
- newDoc.setFieldValue("headerval", new IntegerFieldValue(5678 + (int)e.getTimestamp()));
- spi.put(b, 1000 + e.getTimestamp(), newDoc);
- newDocs.add(new DocEntry(1000 + e.getTimestamp(), newDoc));
- }
-
- spi.flush(b);
-
- CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("", 0, Long.MAX_VALUE), PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY);
-
- List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 4096, 0);
-
- verifyDocs(newDocs, chunks);
-
- spi.destroyIterator(iter.getIteratorId());
- }
-
-
- void testIterateChunked(PersistenceProvider spi) throws Exception
- {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
-
- List<DocEntry> docs = feedDocs(spi, b, 100, 110, 110);
- CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("", 0, Long.MAX_VALUE), PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY);
-
- List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 1, 0);
- assertEquals(100, chunks.size());
- verifyDocs(docs, chunks);
-
- spi.destroyIterator(iter.getIteratorId());
- }
-
- void
- testIterateMaxByteSize(PersistenceProvider spi) throws Exception
- {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
-
- List<DocEntry> docs = feedDocs(spi, b, 100, 4096, 4096);
-
- CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("", 0, Long.MAX_VALUE), PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY);
-
- // Docs are 4k each and iterating with max combined size of 10k.
- // Should receive no more than 3 docs in each chunk
- List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 10000, 0);
- assertTrue("Expected >= 33 chunks, got " + chunks.size(), chunks.size() >= 33);
- verifyDocs(docs, chunks);
-
- spi.destroyIterator(iter.getIteratorId());
- }
-
- void
- testIterateMatchTimestampRange(PersistenceProvider spi) throws Exception
- {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
-
- List<DocEntry> docsToVisit = new ArrayList<DocEntry>();
-
- long fromTimestamp = 1010;
- long toTimestamp = 1060;
-
- for (int i = 0; i < 99; i++) {
- long timestamp = 1000 + i;
-
- Document doc = testDocMan.createRandomDocumentAtLocation(1, timestamp);
-
- spi.put(b, timestamp, doc);
- if (timestamp >= fromTimestamp && timestamp <= toTimestamp) {
- docsToVisit.add(new DocEntry(timestamp, doc));
- }
- }
- spi.flush(b);
-
- CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("", fromTimestamp, toTimestamp),
- PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY);
-
- List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 2048, 0);
- verifyDocs(docsToVisit, chunks);
-
- spi.destroyIterator(iter.getIteratorId());
- }
-
- void testIterateExplicitTimestampSubset(PersistenceProvider spi) throws Exception {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
-
- List<DocEntry> docsToVisit = new ArrayList<DocEntry>();
- Set<Long> timestampsToVisit = new TreeSet<Long>();
- List<String> removes = new ArrayList<String>();
-
-
- for (int i = 0; i < 99; i++) {
- long timestamp = 1000 + i;
- Document doc = testDocMan.createRandomDocumentAtLocation(1, timestamp, 110, 110);
-
- spi.put(b, timestamp, doc);
- if (timestamp % 3 == 0) {
- docsToVisit.add(new DocEntry(timestamp, doc));
- timestampsToVisit.add(timestamp);
- }
- }
-
- assertTrue(spi.remove(b, 2000, docsToVisit.get(0).getDocument().getId()).wasFound());
- spi.flush(b);
-
- timestampsToVisit.add(2000l);
- removes.add(docsToVisit.get(0).getDocument().getId().toString());
- timestampsToVisit.remove(docsToVisit.get(0).getTimestamp());
- docsToVisit.remove(docsToVisit.get(0));
-
- // When selecting a timestamp subset, we should ignore IncludedVersions, and return all matches regardless.
- CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection(timestampsToVisit),
- PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY);
-
- List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 2048, 0);
-
- verifyDocs(docsToVisit, chunks, removes);
-
- spi.destroyIterator(iter.getIteratorId());
- }
-
- void testIterateRemoves(PersistenceProvider spi) throws Exception {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
-
- int docCount = 10;
- List<DocEntry> docs = feedDocs(spi, b, docCount, 100, 100);
- List<String> removedDocs = new ArrayList<String>();
- List<DocEntry> nonRemovedDocs = new ArrayList<DocEntry>();
-
- for (int i = 0; i < docCount; ++i) {
- if (i % 3 == 0) {
- removedDocs.add(docs.get(i).getDocument().getId().toString());
- assertTrue(spi.remove(b, 2000 + i, docs.get(i).getDocument().getId()).wasFound());
- } else {
- nonRemovedDocs.add(docs.get(i));
- }
- }
- spi.flush(b);
-
- // First, test iteration without removes
- {
- CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("", 0, Long.MAX_VALUE),
- PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY);
-
- List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 4096, 0);
- verifyDocs(nonRemovedDocs, chunks);
- spi.destroyIterator(iter.getIteratorId());
- }
-
- {
- CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("", 0, Long.MAX_VALUE),
- PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_OR_REMOVE);
-
- List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 4096, 0);
- verifyDocs(nonRemovedDocs, chunks, removedDocs);
- spi.destroyIterator(iter.getIteratorId());
- }
- }
-
- void testIterateMatchSelection(PersistenceProvider spi) throws Exception
- {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
-
- List<DocEntry> docsToVisit = new ArrayList<DocEntry>();
-
- for (int i = 0; i < 99; i++) {
- Document doc = testDocMan.createRandomDocumentAtLocation(1, 1000 + i, 110, 110);
- doc.setFieldValue("headerval", new IntegerFieldValue(i));
-
- spi.put(b, 1000 + i, doc);
- if ((i % 3) == 0) {
- docsToVisit.add(new DocEntry(1000 + i, doc));
- }
- }
- spi.flush(b);
-
- CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("testdoctype1.headerval % 3 == 0", 0, Long.MAX_VALUE),
- PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY);
-
- List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 2048, 0);
- verifyDocs(docsToVisit, chunks);
-
- spi.destroyIterator(iter.getIteratorId());
- }
-
- void testIterationRequiringDocumentIdOnlyMatching(PersistenceProvider spi) throws Exception
- {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
-
- feedDocs(spi, b, 100, 100, 100);
- DocumentId removedId = new DocumentId("userdoc:blarg:1:unknowndoc");
-
- // Document does not already exist, remove should create a
- // remove entry for it regardless.
- assertFalse(spi.remove(b, 2000, removedId).wasFound());
- spi.flush(b);
-
- CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("id == '" + removedId.toString() + "'", 0, Long.MAX_VALUE),
- PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_OR_REMOVE);
-
- List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 4096, 0);
- List<String> removes = new ArrayList<String>();
- List<DocEntry> docs = new ArrayList<DocEntry>();
-
- removes.add(removedId.toString());
- verifyDocs(docs, chunks, removes);
-
- spi.destroyIterator(iter.getIteratorId());
- }
-
- void testIterateAlreadyCompleted(PersistenceProvider spi) throws Exception
- {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
-
- List<DocEntry> docs = feedDocs(spi, b, 10, 100, 100);
- CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("", 0, Long.MAX_VALUE),
- PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_OR_REMOVE);
-
- List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 4096, 0);
- verifyDocs(docs, chunks);
-
- IterateResult result = spi.iterate(iter.getIteratorId(), 4096);
- assertEquals(Result.ErrorType.NONE, result.getErrorType());
- assertEquals(0, result.getEntries().size());
- assertTrue(result.isCompleted());
-
- spi.destroyIterator(iter.getIteratorId());
- }
-
- void testIterateEmptyBucket(PersistenceProvider spi) throws Exception
- {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
-
- CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("", 0, Long.MAX_VALUE),
- PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_OR_REMOVE);
-
- IterateResult result = spi.iterate(iter.getIteratorId(), 4096);
- assertEquals(Result.ErrorType.NONE, result.getErrorType());
- assertEquals(0, result.getEntries().size());
- assertTrue(result.isCompleted());
-
- spi.destroyIterator(iter.getIteratorId());
- }
-
- void testDeleteBucket(PersistenceProvider spi) throws Exception
- {
- Bucket b = new Bucket((short)0, new BucketId(8, 0x1));
- spi.createBucket(b);
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
-
- spi.put(b, 3, doc1);
- spi.flush(b);
-
- spi.deleteBucket(b);
- GetResult result = spi.get(b, new AllFields(), doc1.getId());
-
- assertEquals(Result.ErrorType.NONE, result.getErrorType());
- assertEquals(0, result.getLastModifiedTimestamp());
- }
-
-
- void testSplitNormalCase(PersistenceProvider spi)
- {
- Bucket bucketA = new Bucket((short)0, new BucketId(3, 0x2));
- Bucket bucketB = new Bucket((short)0, new BucketId(3, 0x6));
-
- Bucket bucketC = new Bucket((short)0, new BucketId(2, 0x2));
- spi.createBucket(bucketC);
-
- for (int i = 0; i < 10; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i);
- spi.put(bucketC, i + 1, doc1);
- }
-
- for (int i = 10; i < 20; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i);
- spi.put(bucketC, i + 1, doc1);
- }
-
- spi.flush(bucketC);
-
- spi.split(bucketC, bucketA, bucketB);
- testSplitNormalCasePostCondition(spi, bucketA, bucketB, bucketC);
- /*if (_factory->hasPersistence()) {
- spi.reset();
- document::TestDocMan testDocMan2;
- spi = getSpi(*_factory, testDocMan2);
- testSplitNormalCasePostCondition(spi, bucketA, bucketB, bucketC,
- testDocMan2);
- }*/
- }
-
-
- void testSplitNormalCasePostCondition(PersistenceProvider spi, Bucket bucketA,
- Bucket bucketB, Bucket bucketC)
- {
- assertEquals(10, spi.getBucketInfo(bucketA).getBucketInfo().
- getDocumentCount());
- assertEquals(10, spi.getBucketInfo(bucketB).getBucketInfo().
- getDocumentCount());
-
- FieldSet fs = new AllFields();
- for (int i = 0; i < 10; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i);
- assertTrue(spi.get(bucketA, fs, doc1.getId()).hasDocument());
- assertTrue(!spi.get(bucketC, fs, doc1.getId()).hasDocument());
- assertTrue(!spi.get(bucketB, fs, doc1.getId()).hasDocument());
- }
-
- for (int i = 10; i < 20; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i);
- assertTrue(spi.get(bucketB, fs, doc1.getId()).hasDocument());
- assertTrue(!spi.get(bucketA, fs, doc1.getId()).hasDocument());
- assertTrue(!spi.get(bucketC, fs, doc1.getId()).hasDocument());
- }
- }
-
- void testSplitTargetExists(PersistenceProvider spi) throws Exception
- {
- Bucket bucketA = new Bucket((short)0, new BucketId(3, 0x2));
- Bucket bucketB = new Bucket((short)0, new BucketId(3, 0x6));
- spi.createBucket(bucketB);
-
- Bucket bucketC = new Bucket((short)0, new BucketId(2, 0x2));
- spi.createBucket(bucketC);
-
- for (int i = 0; i < 10; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i);
- spi.put(bucketC, i + 1, doc1);
- }
-
- spi.flush(bucketC);
-
- for (int i = 10; i < 20; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i);
- spi.put(bucketB, i + 1, doc1);
- }
- spi.flush(bucketB);
- assertTrue(!spi.getBucketInfo(bucketB).getBucketInfo().isActive());
-
- for (int i = 10; i < 20; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i);
- spi.put(bucketC, i + 1, doc1);
- }
- spi.flush(bucketC);
-
- for (int i = 20; i < 25; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i);
- spi.put(bucketB, i + 1, doc1);
- }
-
- spi.flush(bucketB);
-
- spi.split(bucketC, bucketA, bucketB);
- testSplitTargetExistsPostCondition(spi, bucketA, bucketB, bucketC);
- /*if (_factory->hasPersistence()) {
- spi.reset();
- document::TestDocMan testDocMan2;
- spi = getSpi(*_factory, testDocMan2);
- testSplitTargetExistsPostCondition(spi, bucketA, bucketB, bucketC,
- testDocMan2);
- }*/
- }
-
-
- void testSplitTargetExistsPostCondition(PersistenceProvider spi, Bucket bucketA,
- Bucket bucketB, Bucket bucketC)
- {
- assertEquals(10, spi.getBucketInfo(bucketA).getBucketInfo().
- getDocumentCount());
- assertEquals(15, spi.getBucketInfo(bucketB).getBucketInfo().
- getDocumentCount());
-
- FieldSet fs = new AllFields();
- for (int i = 0; i < 10; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i);
- assertTrue(spi.get(bucketA, fs, doc1.getId()).hasDocument());
- assertTrue(!spi.get(bucketC, fs, doc1.getId()).hasDocument());
- assertTrue(!spi.get(bucketB, fs, doc1.getId()).hasDocument());
- }
-
- for (int i = 10; i < 25; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i);
- assertTrue(spi.get(bucketB, fs, doc1.getId()).hasDocument());
- assertTrue(!spi.get(bucketA, fs, doc1.getId()).hasDocument());
- assertTrue(!spi.get(bucketC, fs, doc1.getId()).hasDocument());
- }
- }
-
- void testJoinNormalCase(PersistenceProvider spi) throws Exception
- {
- Bucket bucketA = new Bucket((short)0, new BucketId(3, 0x02));
- spi.createBucket(bucketA);
-
- Bucket bucketB = new Bucket((short)0, new BucketId(3, 0x06));
- spi.createBucket(bucketB);
-
- Bucket bucketC = new Bucket((short)0, new BucketId(2, 0x02));
-
- for (int i = 0; i < 10; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i);
- spi.put(bucketA, i + 1, doc1);
- }
-
- spi.flush(bucketA);
-
- for (int i = 10; i < 20; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i);
- spi.put(bucketB, i + 1, doc1);
- }
-
- spi.flush(bucketB);
-
- spi.join(bucketA, bucketB, bucketC);
- testJoinNormalCasePostCondition(spi, bucketA, bucketB, bucketC);
- /*if (_factory->hasPersistence()) {
- spi.reset();
- document::TestDocMan testDocMan2;
- spi = getSpi(*_factory, testDocMan2);
- testJoinNormalCasePostCondition(spi, bucketA, bucketB, bucketC,
- testDocMan2);
- }*/
- }
-
- void testJoinNormalCasePostCondition(PersistenceProvider spi, Bucket bucketA,
- Bucket bucketB, Bucket bucketC)
- {
- assertEquals(20, spi.getBucketInfo(bucketC).
- getBucketInfo().getDocumentCount());
-
- FieldSet fs = new AllFields();
- for (int i = 0; i < 10; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i);
- assertTrue(spi.get(bucketC, fs, doc1.getId()).hasDocument());
- assertTrue(!spi.get(bucketA, fs, doc1.getId()).hasDocument());
- }
-
- for (int i = 10; i < 20; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i);
- assertTrue(spi.get(bucketC, fs, doc1.getId()).hasDocument());
- assertTrue(!spi.get(bucketB, fs, doc1.getId()).hasDocument());
- }
- }
-
- void testJoinTargetExists(PersistenceProvider spi) throws Exception
- {
- Bucket bucketA = new Bucket((short)0, new BucketId(3, 0x02));
- spi.createBucket(bucketA);
-
- Bucket bucketB = new Bucket((short)0, new BucketId(3, 0x06));
- spi.createBucket(bucketB);
-
- Bucket bucketC = new Bucket((short)0, new BucketId(2, 0x02));
- spi.createBucket(bucketC);
-
- for (int i = 0; i < 10; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i);
- spi.put(bucketA, i + 1, doc1);
- }
-
- spi.flush(bucketA);
-
- for (int i = 10; i < 20; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i);
- spi.put(bucketB, i + 1, doc1);
- }
- spi.flush(bucketB);
-
- for (int i = 20; i < 30; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i);
- spi.put(bucketC, i + 1, doc1);
- }
- spi.flush(bucketC);
-
- spi.join(bucketA, bucketB, bucketC);
- testJoinTargetExistsPostCondition(spi, bucketA, bucketB, bucketC);
- /*if (_factory->hasPersistence()) {
- spi.reset();
- document::TestDocMan testDocMan2;
- spi = getSpi(*_factory, testDocMan2);
- testJoinTargetExistsPostCondition(spi, bucketA, bucketB, bucketC,
- testDocMan2);
- }*/
- }
-
- void testJoinTargetExistsPostCondition(PersistenceProvider spi, Bucket bucketA,
- Bucket bucketB, Bucket bucketC)
- {
- assertEquals(30, spi.getBucketInfo(bucketC).getBucketInfo().
- getDocumentCount());
-
- FieldSet fs = new AllFields();
- for (int i = 0; i < 10; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i);
- assertTrue(spi.get(bucketC, fs, doc1.getId()).hasDocument());
- assertTrue(!spi.get(bucketA, fs, doc1.getId()).hasDocument());
- }
-
- for (int i = 10; i < 20; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i);
- assertTrue(spi.get(bucketC, fs, doc1.getId()).hasDocument());
- assertTrue(!spi.get(bucketB, fs, doc1.getId()).hasDocument());
- }
-
- for (int i = 20; i < 30; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i);
- assertTrue(spi.get(bucketC, fs, doc1.getId()).hasDocument());
- }
- }
-
- void testJoinOneBucket(PersistenceProvider spi) throws Exception
- {
- Bucket bucketA = new Bucket((short)0, new BucketId(3, 0x02));
- spi.createBucket(bucketA);
-
- Bucket bucketB = new Bucket((short)0, new BucketId(3, 0x06));
- Bucket bucketC = new Bucket((short)0, new BucketId(2, 0x02));
-
- for (int i = 0; i < 10; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i);
- spi.put(bucketA, i + 1, doc1);
- }
- spi.flush(bucketA);
-
- spi.join(bucketA, bucketB, bucketC);
- testJoinOneBucketPostCondition(spi, bucketA, bucketC);
- /*if (_factory->hasPersistence()) {
- spi.reset();
- document::TestDocMan testDocMan2;
- spi = getSpi(*_factory, testDocMan2);
- testJoinOneBucketPostCondition(spi, bucketA, bucketC, testDocMan2);
- }*/
- }
-
- void testJoinOneBucketPostCondition(PersistenceProvider spi, Bucket bucketA, Bucket bucketC)
- {
- assertEquals(10, spi.getBucketInfo(bucketC).getBucketInfo().
- getDocumentCount());
-
- FieldSet fs = new AllFields();
- for (int i = 0; i < 10; ++i) {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i);
- assertTrue(spi.get(bucketC, fs, doc1.getId()).hasDocument());
- assertTrue(!spi.get(bucketA, fs, doc1.getId()).hasDocument());
- }
- }
-
-
- void testMaintain(PersistenceProvider spi) throws Exception {
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
-
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
- spi.createBucket(bucket);
-
- spi.put(bucket, 3, doc1);
- spi.flush(bucket);
-
- assertEquals(Result.ErrorType.NONE,
- spi.maintain(bucket, PersistenceProvider.MaintenanceLevel.LOW).getErrorType());
- }
-
- void testGetModifiedBuckets(PersistenceProvider spi) throws Exception {
- assertEquals(0, spi.getModifiedBuckets().getBuckets().size());
- }
-
- void testBucketActivation(PersistenceProvider spi) throws Exception {
- Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01));
-
- spi.createBucket(bucket);
- {
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
- assertTrue(!info.isActive());
- }
-
- spi.setActiveState(bucket, BucketInfo.ActiveState.ACTIVE);
- {
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
- assertTrue(info.isActive());
- }
-
- spi.setActiveState(bucket, BucketInfo.ActiveState.NOT_ACTIVE);
- {
- BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo();
- assertTrue(!info.isActive());
- }
- }
-
- void testBucketActivationSplitAndJoin(PersistenceProvider spi) throws Exception
- {
- Bucket bucketA = new Bucket((short)0, new BucketId(3, 0x02));
- Bucket bucketB = new Bucket((short)0, new BucketId(3, 0x06));
- Bucket bucketC = new Bucket((short)0, new BucketId(2, 0x02));
- Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, 1);
- Document doc2 = testDocMan.createRandomDocumentAtLocation(0x06, 2);
-
- spi.createBucket(bucketC);
- spi.put(bucketC, 1, doc1);
- spi.put(bucketC, 2, doc2);
- spi.flush(bucketC);
-
- spi.setActiveState(bucketC, BucketInfo.ActiveState.ACTIVE);
- assertTrue(spi.getBucketInfo(bucketC).getBucketInfo().isActive());
- spi.split(bucketC, bucketA, bucketB);
- assertTrue(spi.getBucketInfo(bucketA).getBucketInfo().isActive());
- assertTrue(spi.getBucketInfo(bucketB).getBucketInfo().isActive());
- assertTrue(!spi.getBucketInfo(bucketC).getBucketInfo().isActive());
-
- spi.setActiveState(bucketA, BucketInfo.ActiveState.NOT_ACTIVE);
- spi.setActiveState(bucketB, BucketInfo.ActiveState.NOT_ACTIVE);
- spi.join(bucketA, bucketB, bucketC);
- assertTrue(!spi.getBucketInfo(bucketA).getBucketInfo().isActive());
- assertTrue(!spi.getBucketInfo(bucketB).getBucketInfo().isActive());
- assertTrue(!spi.getBucketInfo(bucketC).getBucketInfo().isActive());
-
- spi.split(bucketC, bucketA, bucketB);
- assertTrue(!spi.getBucketInfo(bucketA).getBucketInfo().isActive());
- assertTrue(!spi.getBucketInfo(bucketB).getBucketInfo().isActive());
- assertTrue(!spi.getBucketInfo(bucketC).getBucketInfo().isActive());
-
- spi.setActiveState(bucketA, BucketInfo.ActiveState.ACTIVE);
- spi.join(bucketA, bucketB, bucketC);
- assertTrue(!spi.getBucketInfo(bucketA).getBucketInfo().isActive());
- assertTrue(!spi.getBucketInfo(bucketB).getBucketInfo().isActive());
- assertTrue(spi.getBucketInfo(bucketC).getBucketInfo().isActive());
- }
-//
-// void testRemoveEntry()
-// {
-// if (!_factory->supportsRemoveEntry()) {
-// return;
-// }
-// document::TestDocMan testDocMan;
-// _factory->clear();
-// PersistenceProvider::UP spi(getSpi(*_factory, testDocMan));
-//
-// Bucket bucket(document::BucketId(8, 0x01), PartitionId(0));
-// Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1);
-// Document doc2 = testDocMan.createRandomDocumentAtLocation(0x01, 2);
-// spi.createBucket(bucket);
-//
-// spi.put(bucket, 3, doc1);
-// spi.flush(bucket);
-// BucketInfo info1 = spi.getBucketInfo(bucket).getBucketInfo();
-//
-// {
-// spi.put(bucket, 4, doc2);
-// spi.flush(bucket);
-// spi.removeEntry(bucket, 4);
-// spi.flush(bucket);
-// BucketInfo info2 = spi.getBucketInfo(bucket).getBucketInfo();
-// assertEquals(info1, info2);
-// }
-//
-// // Test case where there exists a previous version of the document.
-// {
-// spi.put(bucket, 5, doc1);
-// spi.flush(bucket);
-// spi.removeEntry(bucket, 5);
-// spi.flush(bucket);
-// BucketInfo info2 = spi.getBucketInfo(bucket).getBucketInfo();
-// assertEquals(info1, info2);
-// }
-//
-// // Test case where the newest document version after removeEntrying is a remove.
-// {
-// spi.remove(bucket, 6, doc1.getId());
-// spi.flush(bucket);
-// BucketInfo info2 = spi.getBucketInfo(bucket).getBucketInfo();
-// assertEquals(0, info2.getDocumentCount());
-//
-// spi.put(bucket, 7, doc1);
-// spi.flush(bucket);
-// spi.removeEntry(bucket, 7);
-// spi.flush(bucket);
-// BucketInfo info3 = spi.getBucketInfo(bucket).getBucketInfo();
-// assertEquals(info2, info3);
-// }
-// }
-//
-}
-
-//
-//// Get number of puts and removes across all chunks (i.e. all entries)
-// size_t
-// getDocCount(const std::vector<Chunk>& chunks)
-// {
-// size_t count = 0;
-// for (size_t i=0; i<chunks.size(); ++i) {
-// count += chunks[i]._entries.size();
-// }
-// return count;
-// }
-//
-// size_t
-// getRemoveEntryCount(const std::vector<spi::DocEntry::UP>& entries)
-// {
-// size_t ret = 0;
-// for (size_t i = 0; i < entries.size(); ++i) {
-// if (entries[i]->isRemove()) {
-// ++ret;
-// }
-// }
-// return ret;
-// }
-//
-// List<DocEntry>
-// getEntriesFromChunks(const std::vector<Chunk>& chunks)
-// {
-// std::vector<spi::DocEntry::UP> ret;
-// for (size_t chunk = 0; chunk < chunks.size(); ++chunk) {
-// for (size_t i = 0; i < chunks[chunk]._entries.size(); ++i) {
-// ret.push_back(chunks[chunk]._entries[i]);
-// }
-// }
-// std::sort(ret.begin(),
-// ret.end(),
-// DocEntryIndirectTimestampComparator());
-// return ret;
-// }
-//
-//
-//
-// spi.destroyIterator(iter.getIteratorId());
-// std::sort(ret.begin(),
-// ret.end(),
-// DocEntryIndirectTimestampComparator());
-// return ret;
-// }
-//
-// void
-// verifyDocs(const std::vector<DocAndTimestamp>& wanted,
-// const std::vector<Chunk>& chunks,
-// const std::set<string>& removes = std::set<string>())
-// {
-// List<DocEntry> retrieved(
-// getEntriesFromChunks(chunks));
-// size_t removeCount = getRemoveEntryCount(retrieved);
-// // Ensure that we've got the correct number of puts and removes
-// assertEquals(removes.size(), removeCount);
-// assertEquals(wanted.size(), retrieved.size() - removeCount);
-//
-// size_t wantedIdx = 0;
-// for (size_t i = 0; i < retrieved.size(); ++i) {
-// DocEntry& entry(*retrieved[i]);
-// if (entry.getDocumentOperation() != 0) {
-// if (!(*wanted[wantedIdx].doc == *entry.getDocumentOperation())) {
-// std::ostringstream ss;
-// ss << "Documents differ! Wanted:\n"
-// << wanted[wantedIdx].doc->toString(true)
-// << "\n\nGot:\n"
-// << entry.getDocumentOperation()->toString(true);
-// CPPUNIT_FAIL(ss.str());
-// }
-// assertEquals(wanted[wantedIdx].timestamp, entry.getTimestamp());
-// size_t serSize = wanted[wantedIdx].doc->serialize()->getLength();
-// assertEquals(serSize + sizeof(DocEntry), size_t(entry.getSize()));
-// assertEquals(serSize, size_t(entry.getDocumentSize()));
-// ++wantedIdx;
-// } else {
-// // Remove-entry
-// assertTrue(entry.getDocumentId() != 0);
-// size_t serSize = entry.getDocumentId()->getSerializedSize();
-// assertEquals(serSize + sizeof(DocEntry), size_t(entry.getSize()));
-// assertEquals(serSize, size_t(entry.getDocumentSize()));
-// if (removes.find(entry.getDocumentId()->toString()) == removes.end()) {
-// std::ostringstream ss;
-// ss << "Got unexpected remove entry for document id "
-// << *entry.getDocumentId();
-// CPPUNIT_FAIL(ss.str());
-// }
-// }
-// }
-// }
-//
-//// Feed numDocs documents, starting from timestamp 1000
-//
-// } // namespace
-//
-//
-//
-
-
-
-
-
-// void detectAndTestOptionalBehavior() {
-// // Report if implementation supports setting bucket size info.
-//
-// // Report if joining same bucket on multiple partitions work.
-// // (Where target equals one of the sources). (If not supported service
-// // layer must die if a bucket is found during init on multiple partitions)
-// // Test functionality if it works.
-// }
-//
-//
-// } // spi
-// } // storage
-//
-//
-//}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/conformance/TestDocMan.java b/persistence/src/main/java/com/yahoo/persistence/spi/conformance/TestDocMan.java
deleted file mode 100644
index b002eabe7b8..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/conformance/TestDocMan.java
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi.conformance;
-
-import com.yahoo.document.*;
-import com.yahoo.document.datatypes.IntegerFieldValue;
-import com.yahoo.document.datatypes.StringFieldValue;
-
-public class TestDocMan extends DocumentTypeManager {
-
- public TestDocMan() {
- DocumentType docType = new DocumentType("testdoctype1");
- docType.addHeaderField("headerval", DataType.INT);
- docType.addField("content", DataType.STRING);
-
- registerDocumentType(docType);
- }
-
- public Document createRandomDocumentAtLocation(long location, long timestamp) {
- return createRandomDocumentAtLocation(location, timestamp, 100, 100);
- }
-
- public Document createRandomDocumentAtLocation(long location, long timestamp, int minSize, int maxSize) {
- Document document = new Document(getDocumentType("testdoctype1"),
- new DocumentId("userdoc:footype:" + location + ":" + timestamp));
-
- document.setFieldValue("headerval", new IntegerFieldValue((int)timestamp));
-
- StringBuffer value = new StringBuffer();
- int length = (int)(Math.random() * (maxSize - minSize)) + minSize;
- for (int i = 0; i < length; ++i) {
- value.append("A");
- }
-
- document.setFieldValue("content", new StringFieldValue(value.toString()));
- return document;
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/conformance/package-info.java b/persistence/src/main/java/com/yahoo/persistence/spi/conformance/package-info.java
deleted file mode 100644
index 32180a07983..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/conformance/package-info.java
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-@ExportPackage
-@PublicApi
-package com.yahoo.persistence.spi.conformance;
-
-import com.yahoo.api.annotations.PublicApi;
-import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/package-info.java b/persistence/src/main/java/com/yahoo/persistence/spi/package-info.java
deleted file mode 100644
index 179e9029f73..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/package-info.java
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-@ExportPackage
-@PublicApi
-package com.yahoo.persistence.spi;
-
-import com.yahoo.api.annotations.PublicApi;
-import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/result/BucketIdListResult.java b/persistence/src/main/java/com/yahoo/persistence/spi/result/BucketIdListResult.java
deleted file mode 100644
index c02b7384fe5..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/result/BucketIdListResult.java
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi.result;
-
-import com.yahoo.document.BucketId;
-
-import java.util.List;
-
-/**
- * Result class used for bucket id list requests.
- */
-public class BucketIdListResult extends Result {
- List<BucketId> buckets;
-
- /**
- * Creates a result with an error.
- *
- * @param type The type of error
- * @param message A human-readable error message to further detail the error.
- */
- public BucketIdListResult(ErrorType type, String message) {
- super(type, message);
- }
-
- /**
- * Creates a result containing a list of all the buckets the requested partition has.
- *
- * @param buckets The list of buckets.
- */
- public BucketIdListResult(List<BucketId> buckets) {
- this.buckets = buckets;
- }
-
- public List<BucketId> getBuckets() {
- return buckets;
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/result/BucketInfoResult.java b/persistence/src/main/java/com/yahoo/persistence/spi/result/BucketInfoResult.java
deleted file mode 100644
index e6e9d4a898e..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/result/BucketInfoResult.java
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi.result;
-
-import com.yahoo.persistence.spi.BucketInfo;
-
-/**
- * Result class for the getBucketInfo() function.
- */
-public class BucketInfoResult extends Result {
- BucketInfo bucketInfo = null;
-
- /**
- * Constructor to use for a result where an error has been detected.
- * The service layer will not update the bucket information in this case,
- * so it should not be returned either.
- *
- * @param type The type of error.
- * @param message A human readable message further detailing the error.
- */
- public BucketInfoResult(ErrorType type, String message) {
- super(type, message);
- }
-
- /**
- * Constructor to use when the write operation was successful,
- * and the bucket info was modified.
- *
- * @param info Returns the information about the bucket.
- */
- public BucketInfoResult(BucketInfo info) {
- this.bucketInfo = info;
- }
-
- public BucketInfo getBucketInfo() {
- return bucketInfo;
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/result/CreateIteratorResult.java b/persistence/src/main/java/com/yahoo/persistence/spi/result/CreateIteratorResult.java
deleted file mode 100644
index 28df8a7f5a3..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/result/CreateIteratorResult.java
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi.result;
-
-/**
- * Result class for CreateIterator requests.
- */
-public class CreateIteratorResult extends Result {
- long iteratorId = 0;
-
- /**
- * Creates a result with an error.
- *
- * @param type The type of error
- * @param message A human-readable error message to further detail the error.
- */
- public CreateIteratorResult(Result.ErrorType type, String message) {
- super(type, message);
- }
-
- /**
- * Creates a successful result, containing a unique identifier for this iterator
- * (must be created and maintained by the provider).
- *
- * @param iteratorId The iterator ID to use for this iterator.
- */
- public CreateIteratorResult(long iteratorId) {
- this.iteratorId = iteratorId;
- }
-
- public long getIteratorId() {
- return iteratorId;
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/result/GetResult.java b/persistence/src/main/java/com/yahoo/persistence/spi/result/GetResult.java
deleted file mode 100644
index c74d81730ee..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/result/GetResult.java
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi.result;
-
-import com.yahoo.document.Document;
-
-/**
- * Result class for Get operations
- */
-public class GetResult extends Result {
- Document doc;
- long lastModifiedTimestamp = 0;
-
- /**
- * Constructor to use when there was an error retrieving the document.
- * Not finding the document is not an error in this context.
- *
- * @param type The type of error.
- * @param message A human readable message further detailing the error.
- */
- GetResult(ErrorType type, String message) {
- super(type, message);
- }
-
- /**
- * Constructor to use when we didn't find the document in question.
- */
- public GetResult() {}
-
- /**
- * Constructor to use when we found the document asked for.
- *
- * @param doc The document we found
- * @param lastModifiedTimestamp The timestamp with which the document was stored.
- */
- public GetResult(Document doc, long lastModifiedTimestamp) {
- this.doc = doc;
- this.lastModifiedTimestamp = lastModifiedTimestamp;
- }
-
- /**
- * @return Returns the timestamp at which the document was last modified, or 0 if
- * no document was found.
- */
- public long getLastModifiedTimestamp() { return lastModifiedTimestamp;}
-
- /**
- * @return Returns true if the document was found.
- */
- public boolean wasFound() {
- return doc != null;
- }
-
- public boolean hasDocument() {
- return doc != null;
- }
-
- public Document getDocument() {
- return doc;
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/result/IterateResult.java b/persistence/src/main/java/com/yahoo/persistence/spi/result/IterateResult.java
deleted file mode 100644
index ae9ce4ecf26..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/result/IterateResult.java
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi.result;
-
-import com.yahoo.persistence.spi.DocEntry;
-
-import java.util.List;
-
-/**
- * Result class for iterate requests
- */
-public class IterateResult extends Result {
- List<DocEntry> entries = null;
- boolean isCompleted = false;
-
- /**
- * Creates a result with an error.
- *
- * @param type The type of error
- * @param message A human-readable error message to further detail the error.
- */
- public IterateResult(Result.ErrorType type, String message) {
- super(type, message);
- }
-
- /**
- * Creates a successful result.
- *
- * @param entries The next chunk of entries that were found during iteration.
- * @param isCompleted Set to true if there are no more entries to iterate through.
- */
- public IterateResult(List<DocEntry> entries, boolean isCompleted) {
- this.entries = entries;
- this.isCompleted = isCompleted;
- }
-
- public List<DocEntry> getEntries() {
- return entries;
- }
-
- public boolean isCompleted() {
- return isCompleted;
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/result/PartitionStateListResult.java b/persistence/src/main/java/com/yahoo/persistence/spi/result/PartitionStateListResult.java
deleted file mode 100644
index 5989b6bc3ac..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/result/PartitionStateListResult.java
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi.result;
-
-import com.yahoo.persistence.spi.PartitionState;
-
-import java.util.List;
-
-/**
- * A result class for getPartitionState() requests.
- */
-public class PartitionStateListResult extends Result {
- List<PartitionState> partitionStates = null;
-
- /**
- * Creates a result with an error.
- *
- * @param type The type of error
- * @param message A human-readable error message to further detail the error.
- */
- public PartitionStateListResult(Result.ErrorType type, String message) {
- super(type, message);
- }
-
- /**
- * Creates a result containing a list of all the partitions this provider has,
- * and their states.
- *
- * @param partitions A map containing all the partitions
- */
- public PartitionStateListResult(List<PartitionState> partitions) {
- this.partitionStates = partitions;
- }
-
- public List<PartitionState> getPartitionStates() {
- return partitionStates;
- }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/result/RemoveResult.java b/persistence/src/main/java/com/yahoo/persistence/spi/result/RemoveResult.java
deleted file mode 100644
index eb7abe9f5c4..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/result/RemoveResult.java
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi.result;
-
-import com.yahoo.persistence.spi.BucketInfo;
-
-/**
- * Result class for Remove operations
- */
-public class RemoveResult extends Result {
- boolean wasFound = false;
-
- /**
- * Constructor to use when an error occurred during the update
- *
- * @param error The type of error that occurred
- * @param message A human readable message further detailing the error.
- */
- public RemoveResult(Result.ErrorType error, String message) {
- super(error, message);
- }
-
- /**
- * Constructor to use when there was no document to remove.
- */
- public RemoveResult() {}
-
- /**
- * Constructor to use when the update was successful.
- *
- * @param wasFound The timestamp of the document that was updated.
- */
- public RemoveResult(boolean wasFound) {
- this.wasFound = wasFound;
- }
-
- @Override
- public boolean equals(Object other) {
- if (other instanceof RemoveResult) {
- return super.equals((Result)other) &&
- wasFound == ((RemoveResult)other).wasFound;
- }
-
- return false;
- }
-
- public boolean wasFound() { return wasFound; }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/result/Result.java b/persistence/src/main/java/com/yahoo/persistence/spi/result/Result.java
deleted file mode 100644
index 78d7326fb12..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/result/Result.java
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi.result;
-
-/**
- * Represents a result from an SPI method invocation.
- */
-public class Result {
-
- /**
- * Enumeration of the various categories of errors that can be returned
- * in a result.
- *
- * The categories are:
- *
- * TRANSIENT_ERROR: Operation failed, but may succeed if attempted again or on other data copies
- * PERMANENT_ERROR: Operation failed because it was somehow malformed or the operation parameters were wrong. Operation won't succeed
- * on other data copies either.
- * FATAL_ERROR: Operation failed in such a way that this node should be stopped (for instance, a disk failure). Operation will be retried
- * on other data copies.
- */
- public enum ErrorType {
- NONE,
- TRANSIENT_ERROR,
- PERMANENT_ERROR,
- UNUSED_ID,
- FATAL_ERROR
- }
-
- /**
- * Constructor to use for a result where there is no error.
- */
- public Result() {
- }
-
- /**
- * Creates a result with an error.
- *
- * @param type The type of error
- * @param message A human-readable error message to further detail the error.
- */
- public Result(ErrorType type, String message) {
- this.type = type;
- this.message = message;
- }
-
- public boolean equals(Result other) {
- return type.equals(other.type) &&
- message.equals(other.message);
- }
-
- @Override
- public boolean equals(Object otherResult) {
- if (otherResult instanceof Result) {
- return equals((Result)otherResult);
- }
-
- return false;
- }
-
- public boolean hasError() {
- return type != ErrorType.NONE;
- }
-
- public ErrorType getErrorType() {
- return type;
- }
-
- public String getErrorMessage() {
- return message;
- }
-
- @Override
- public String toString() {
- if (type == null) {
- return "Result(OK)";
- }
-
- return "Result(" + type.toString() + ", " + message + ")";
- }
-
- ErrorType type = ErrorType.NONE;
- String message = "";
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/result/UpdateResult.java b/persistence/src/main/java/com/yahoo/persistence/spi/result/UpdateResult.java
deleted file mode 100644
index 97bccdb21b7..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/result/UpdateResult.java
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.persistence.spi.result;
-
-import com.yahoo.persistence.spi.BucketInfo;
-
-/**
- * Result class for update operations.
- */
-public class UpdateResult extends Result {
- long existingTimestamp = 0;
-
- /**
- * Constructor to use when an error occurred during the update
- *
- * @param error The type of error that occurred
- * @param message A human readable message further detailing the error.
- */
- public UpdateResult(ErrorType error, String message) {
- super(error, message);
- }
-
- /**
- * Constructor to use when the document to update was not found.
- */
- public UpdateResult() {
- super();
- }
-
- /**
- * Constructor to use when the update was successful.
- *
- * @param existingTimestamp The timestamp of the document that was updated.
- */
- public UpdateResult(long existingTimestamp) {
- this.existingTimestamp = existingTimestamp;
- }
-
- public long getExistingTimestamp() { return existingTimestamp; }
-}
diff --git a/persistence/src/main/java/com/yahoo/persistence/spi/result/package-info.java b/persistence/src/main/java/com/yahoo/persistence/spi/result/package-info.java
deleted file mode 100644
index 06a40dec719..00000000000
--- a/persistence/src/main/java/com/yahoo/persistence/spi/result/package-info.java
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-@ExportPackage
-@PublicApi
-package com.yahoo.persistence.spi.result;
-
-import com.yahoo.api.annotations.PublicApi;
-import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/persistence/src/main/resources/configdefinitions/persistence-rpc.def b/persistence/src/main/resources/configdefinitions/persistence-rpc.def
deleted file mode 100644
index 9cae5812760..00000000000
--- a/persistence/src/main/resources/configdefinitions/persistence-rpc.def
+++ /dev/null
@@ -1,4 +0,0 @@
-# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-namespace=persistence
-
-port int default=3456 restart