You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2017/08/16 15:26:29 UTC
svn commit: r1805209 - in /jackrabbit/oak/trunk/oak-segment-tar: ./
src/main/java/org/apache/jackrabbit/oak/segment/file/
src/main/java/org/apache/jackrabbit/oak/segment/file/tar/
src/test/java/org/apache/jackrabbit/oak/segment/upgrade/ src/test/upgrad...
Author: mduerig
Date: Wed Aug 16 15:26:29 2017
New Revision: 1805209
URL: http://svn.apache.org/viewvc?rev=1805209&view=rev
Log:
OAK-6555: Implement ITs for rolling upgrade
Added:
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java
jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/
jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy
Modified:
jackrabbit/oak/trunk/oak-segment-tar/pom.xml
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java
Modified: jackrabbit/oak/trunk/oak-segment-tar/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/pom.xml?rev=1805209&r1=1805208&r2=1805209&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/pom.xml Wed Aug 16 15:26:29 2017
@@ -87,6 +87,40 @@
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>pre-integration-test</phase>
+ <goals><goal>copy</goal></goals>
+ <configuration>
+ <artifact>org.apache.jackrabbit:oak-run:1.6.1</artifact>
+ <outputDirectory>${project.build.directory}/upgrade-it</outputDirectory>
+ <stripVersion>true</stripVersion>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>pre-integration-test</phase>
+ <goals><goal>copy-resources</goal></goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/upgrade-it</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/test/upgrade-it-scripts</directory>
+ <filtering>false</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java?rev=1805209&r1=1805208&r2=1805209&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java Wed Aug 16 15:26:29 2017
@@ -22,9 +22,9 @@ import static com.google.common.base.Pre
import java.io.File;
import java.io.IOException;
-class ManifestChecker {
+public class ManifestChecker {
- static ManifestChecker newManifestChecker(File path, boolean shouldExist, int minStoreVersion, int maxStoreVersion) {
+ public static ManifestChecker newManifestChecker(File path, boolean shouldExist, int minStoreVersion, int maxStoreVersion) {
checkArgument(path != null, "path");
checkArgument(minStoreVersion > 0, "minStoreVersion");
checkArgument(maxStoreVersion > 0, "maxStoreVersion");
@@ -52,7 +52,7 @@ class ManifestChecker {
updateManifest(manifest);
}
- void checkManifest() throws IOException, InvalidFileStoreVersionException {
+ public void checkManifest() throws IOException, InvalidFileStoreVersionException {
checkManifest(openManifest());
}
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java?rev=1805209&r1=1805208&r2=1805209&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java Wed Aug 16 15:26:29 2017
@@ -26,6 +26,16 @@ import java.io.File;
public interface IOMonitor {
/**
+ * A trivial instance of {@code IOMonitor} that does nothing.
+ */
+ IOMonitor NULL = new IOMonitor(){
+ @Override public void beforeSegmentRead(File file, long msb, long lsb, int length) {}
+ @Override public void afterSegmentRead(File file, long msb, long lsb, int length, long elapsed) {}
+ @Override public void beforeSegmentWrite(File file, long msb, long lsb, int length) {}
+ @Override public void afterSegmentWrite(File file, long msb, long lsb, int length, long elapsed) {}
+ };
+
+ /**
* Called before a segment is read from the file system.
*
* @param file File containing the segment.
Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java?rev=1805209&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java Wed Aug 16 15:26:29 2017
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jackrabbit.oak.segment.upgrade;
+
+import static com.google.common.collect.Iterables.transform;
+import static java.lang.String.format;
+import static java.util.concurrent.TimeUnit.MINUTES;
+import static org.apache.jackrabbit.oak.segment.SegmentVersion.V_12;
+import static org.apache.jackrabbit.oak.segment.SegmentVersion.V_13;
+import static org.apache.jackrabbit.oak.segment.data.SegmentData.newSegmentData;
+import static org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder;
+import static org.apache.jackrabbit.oak.segment.file.ManifestChecker.newManifestChecker;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.ProcessBuilder.Redirect;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.segment.SegmentVersion;
+import org.apache.jackrabbit.oak.segment.data.SegmentData;
+import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
+import org.apache.jackrabbit.oak.segment.file.tar.IOMonitor;
+import org.apache.jackrabbit.oak.segment.file.tar.TarFiles;
+import org.apache.jackrabbit.oak.segment.tool.Compact;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class UpgradeIT {
+
+ private final File upgradeItHome = new File("target/upgrade-it");
+
+ @Rule
+ public TemporaryFolder fileStoreHome = new TemporaryFolder(upgradeItHome);
+
+ /**
+ * Launch a groovy script in an Oak 1.6. console to initialise the upgrade
+ * source. See pom.xml for how these files are placed under target/upgrade-it.
+ */
+ @Before
+ public void setup() throws IOException, InterruptedException {
+ Process oakConsole = new ProcessBuilder(
+ "java", "-jar", "oak-run.jar",
+ "console", fileStoreHome.getRoot().getAbsolutePath(), "--read-write",
+ ":load create16store.groovy")
+ .directory(upgradeItHome)
+ .redirectError(Redirect.INHERIT)
+ .redirectOutput(Redirect.INHERIT)
+ .redirectInput(Redirect.INHERIT)
+ .start();
+
+ assertTrue(
+ "Timeout while creating the source repository",
+ oakConsole.waitFor(2, MINUTES));
+ }
+
+ @Test
+ public void openUpgradesStore() throws IOException, InvalidFileStoreVersionException {
+ checkStoreVersion(1);
+ fileStoreBuilder(fileStoreHome.getRoot())
+ .build()
+ .close();
+ checkStoreVersion(2);
+ }
+
+ @Test
+ public void openReadonlyDoesNotUpgradeStore() throws IOException, InvalidFileStoreVersionException {
+ checkStoreVersion(1);
+ fileStoreBuilder(fileStoreHome.getRoot())
+ .buildReadOnly()
+ .close();
+ checkStoreVersion(1);
+ }
+
+ @Test
+ public void offRCUpgradesSegments() throws IOException, InvalidFileStoreVersionException {
+ checkSegmentVersion(V_12);
+ checkStoreVersion(1);
+ Compact.builder()
+ .withPath(fileStoreHome.getRoot())
+ .withMmap(true)
+ .build()
+ .run();
+ checkStoreVersion(2);
+ checkSegmentVersion(V_13);
+ }
+
+ private void checkStoreVersion(int version) throws IOException, InvalidFileStoreVersionException {
+ newManifestChecker(new File(fileStoreHome.getRoot(), "/manifest"),
+ true, version, version).checkManifest();
+ }
+
+ private void checkSegmentVersion(@Nonnull SegmentVersion version) throws IOException {
+ try (TarFiles tarFiles = TarFiles.builder()
+ .withDirectory(fileStoreHome.getRoot())
+ .withTarRecovery((_1, _2, _3) -> fail("Unexpected recovery"))
+ .withIOMonitor(IOMonitor.NULL)
+ .withReadOnly()
+ .build()) {
+
+ for (SegmentData segmentData : getSegments(tarFiles)) {
+ SegmentVersion actualVersion = SegmentVersion.fromByte(segmentData.getVersion());
+ assertEquals(
+ format("Segment version mismatch. Expected %s, found %s", version, actualVersion),
+ version, actualVersion);
+ }
+ }
+ }
+
+ private static Iterable<SegmentData> getSegments(@Nonnull TarFiles tarFiles) {
+ return transform(
+ tarFiles.getSegmentIds(),
+ uuid -> newSegmentData(tarFiles.readSegment(
+ uuid.getMostSignificantBits(),
+ uuid.getLeastSignificantBits())));
+ }
+}
Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy?rev=1805209&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy Wed Aug 16 15:26:29 2017
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import org.apache.jackrabbit.oak.segment.SegmentNodeBuilder
+import org.apache.jackrabbit.oak.spi.commit.EmptyHook
+import org.apache.jackrabbit.oak.spi.commit.CommitInfo
+
+void addNodes(SegmentNodeBuilder builder, int count, int depth) {
+ if (depth > 0) {
+ for (int c = 0; c < count; c++) {
+ builder.setProperty(
+ "property-name-" + depth + "-" + c,
+ "property-value-" + depth + "-" + c)
+ addNodes(
+ builder.setChildNode("node-" + depth + "-" + c),
+ count,
+ depth - 1)
+ }
+ }
+}
+
+nodeStore = session.store
+builder = nodeStore.getRoot().builder()
+addNodes(builder, 10, 5)
+nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
Re: svn commit: r1805209 - in /jackrabbit/oak/trunk/oak-segment-tar:
./ src/main/java/org/apache/jackrabbit/oak/segment/file/ src/main/java/org/apache/jackrabbit/oak/segment/file/tar/
src/test/java/org/apache/jackrabbit/oak/segment/upgrade/ src/test/upgrad...
Posted by Francesco Mari <ma...@gmail.com>.
Instead of creating IOMonitor.NULL, you could instantiate a new
IOMonitorAdapter when needed. This has already been done many times in
TarFileTest and TarWriterTest.
On Wed, Aug 16, 2017 at 5:26 PM, <md...@apache.org> wrote:
> Author: mduerig
> Date: Wed Aug 16 15:26:29 2017
> New Revision: 1805209
>
> URL: http://svn.apache.org/viewvc?rev=1805209&view=rev
> Log:
> OAK-6555: Implement ITs for rolling upgrade
>
> Added:
> jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/
> jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java
> jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/
> jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy
> Modified:
> jackrabbit/oak/trunk/oak-segment-tar/pom.xml
> jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java
> jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java
>
> Modified: jackrabbit/oak/trunk/oak-segment-tar/pom.xml
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/pom.xml?rev=1805209&r1=1805208&r2=1805209&view=diff
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-segment-tar/pom.xml (original)
> +++ jackrabbit/oak/trunk/oak-segment-tar/pom.xml Wed Aug 16 15:26:29 2017
> @@ -87,6 +87,40 @@
> <redirectTestOutputToFile>true</redirectTestOutputToFile>
> </configuration>
> </plugin>
> + <plugin>
> + <groupId>org.apache.maven.plugins</groupId>
> + <artifactId>maven-dependency-plugin</artifactId>
> + <executions>
> + <execution>
> + <phase>pre-integration-test</phase>
> + <goals><goal>copy</goal></goals>
> + <configuration>
> + <artifact>org.apache.jackrabbit:oak-run:1.6.1</artifact>
> + <outputDirectory>${project.build.directory}/upgrade-it</outputDirectory>
> + <stripVersion>true</stripVersion>
> + </configuration>
> + </execution>
> + </executions>
> + </plugin>
> + <plugin>
> + <groupId>org.apache.maven.plugins</groupId>
> + <artifactId>maven-resources-plugin</artifactId>
> + <executions>
> + <execution>
> + <phase>pre-integration-test</phase>
> + <goals><goal>copy-resources</goal></goals>
> + <configuration>
> + <outputDirectory>${project.build.directory}/upgrade-it</outputDirectory>
> + <resources>
> + <resource>
> + <directory>src/test/upgrade-it-scripts</directory>
> + <filtering>false</filtering>
> + </resource>
> + </resources>
> + </configuration>
> + </execution>
> + </executions>
> + </plugin>
> </plugins>
> </build>
>
>
> Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java?rev=1805209&r1=1805208&r2=1805209&view=diff
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java (original)
> +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java Wed Aug 16 15:26:29 2017
> @@ -22,9 +22,9 @@ import static com.google.common.base.Pre
> import java.io.File;
> import java.io.IOException;
>
> -class ManifestChecker {
> +public class ManifestChecker {
>
> - static ManifestChecker newManifestChecker(File path, boolean shouldExist, int minStoreVersion, int maxStoreVersion) {
> + public static ManifestChecker newManifestChecker(File path, boolean shouldExist, int minStoreVersion, int maxStoreVersion) {
> checkArgument(path != null, "path");
> checkArgument(minStoreVersion > 0, "minStoreVersion");
> checkArgument(maxStoreVersion > 0, "maxStoreVersion");
> @@ -52,7 +52,7 @@ class ManifestChecker {
> updateManifest(manifest);
> }
>
> - void checkManifest() throws IOException, InvalidFileStoreVersionException {
> + public void checkManifest() throws IOException, InvalidFileStoreVersionException {
> checkManifest(openManifest());
> }
>
>
> Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java?rev=1805209&r1=1805208&r2=1805209&view=diff
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java (original)
> +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java Wed Aug 16 15:26:29 2017
> @@ -26,6 +26,16 @@ import java.io.File;
> public interface IOMonitor {
>
> /**
> + * A trivial instance of {@code IOMonitor} that does nothing.
> + */
> + IOMonitor NULL = new IOMonitor(){
> + @Override public void beforeSegmentRead(File file, long msb, long lsb, int length) {}
> + @Override public void afterSegmentRead(File file, long msb, long lsb, int length, long elapsed) {}
> + @Override public void beforeSegmentWrite(File file, long msb, long lsb, int length) {}
> + @Override public void afterSegmentWrite(File file, long msb, long lsb, int length, long elapsed) {}
> + };
> +
> + /**
> * Called before a segment is read from the file system.
> *
> * @param file File containing the segment.
>
> Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java?rev=1805209&view=auto
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java (added)
> +++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java Wed Aug 16 15:26:29 2017
> @@ -0,0 +1,138 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + *
> + */
> +
> +package org.apache.jackrabbit.oak.segment.upgrade;
> +
> +import static com.google.common.collect.Iterables.transform;
> +import static java.lang.String.format;
> +import static java.util.concurrent.TimeUnit.MINUTES;
> +import static org.apache.jackrabbit.oak.segment.SegmentVersion.V_12;
> +import static org.apache.jackrabbit.oak.segment.SegmentVersion.V_13;
> +import static org.apache.jackrabbit.oak.segment.data.SegmentData.newSegmentData;
> +import static org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder;
> +import static org.apache.jackrabbit.oak.segment.file.ManifestChecker.newManifestChecker;
> +import static org.junit.Assert.assertEquals;
> +import static org.junit.Assert.assertTrue;
> +import static org.junit.Assert.fail;
> +
> +import java.io.File;
> +import java.io.IOException;
> +import java.lang.ProcessBuilder.Redirect;
> +
> +import javax.annotation.Nonnull;
> +
> +import org.apache.jackrabbit.oak.segment.SegmentVersion;
> +import org.apache.jackrabbit.oak.segment.data.SegmentData;
> +import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
> +import org.apache.jackrabbit.oak.segment.file.tar.IOMonitor;
> +import org.apache.jackrabbit.oak.segment.file.tar.TarFiles;
> +import org.apache.jackrabbit.oak.segment.tool.Compact;
> +import org.junit.Before;
> +import org.junit.Rule;
> +import org.junit.Test;
> +import org.junit.rules.TemporaryFolder;
> +
> +public class UpgradeIT {
> +
> + private final File upgradeItHome = new File("target/upgrade-it");
> +
> + @Rule
> + public TemporaryFolder fileStoreHome = new TemporaryFolder(upgradeItHome);
> +
> + /**
> + * Launch a groovy script in an Oak 1.6. console to initialise the upgrade
> + * source. See pom.xml for how these files are placed under target/upgrade-it.
> + */
> + @Before
> + public void setup() throws IOException, InterruptedException {
> + Process oakConsole = new ProcessBuilder(
> + "java", "-jar", "oak-run.jar",
> + "console", fileStoreHome.getRoot().getAbsolutePath(), "--read-write",
> + ":load create16store.groovy")
> + .directory(upgradeItHome)
> + .redirectError(Redirect.INHERIT)
> + .redirectOutput(Redirect.INHERIT)
> + .redirectInput(Redirect.INHERIT)
> + .start();
> +
> + assertTrue(
> + "Timeout while creating the source repository",
> + oakConsole.waitFor(2, MINUTES));
> + }
> +
> + @Test
> + public void openUpgradesStore() throws IOException, InvalidFileStoreVersionException {
> + checkStoreVersion(1);
> + fileStoreBuilder(fileStoreHome.getRoot())
> + .build()
> + .close();
> + checkStoreVersion(2);
> + }
> +
> + @Test
> + public void openReadonlyDoesNotUpgradeStore() throws IOException, InvalidFileStoreVersionException {
> + checkStoreVersion(1);
> + fileStoreBuilder(fileStoreHome.getRoot())
> + .buildReadOnly()
> + .close();
> + checkStoreVersion(1);
> + }
> +
> + @Test
> + public void offRCUpgradesSegments() throws IOException, InvalidFileStoreVersionException {
> + checkSegmentVersion(V_12);
> + checkStoreVersion(1);
> + Compact.builder()
> + .withPath(fileStoreHome.getRoot())
> + .withMmap(true)
> + .build()
> + .run();
> + checkStoreVersion(2);
> + checkSegmentVersion(V_13);
> + }
> +
> + private void checkStoreVersion(int version) throws IOException, InvalidFileStoreVersionException {
> + newManifestChecker(new File(fileStoreHome.getRoot(), "/manifest"),
> + true, version, version).checkManifest();
> + }
> +
> + private void checkSegmentVersion(@Nonnull SegmentVersion version) throws IOException {
> + try (TarFiles tarFiles = TarFiles.builder()
> + .withDirectory(fileStoreHome.getRoot())
> + .withTarRecovery((_1, _2, _3) -> fail("Unexpected recovery"))
> + .withIOMonitor(IOMonitor.NULL)
> + .withReadOnly()
> + .build()) {
> +
> + for (SegmentData segmentData : getSegments(tarFiles)) {
> + SegmentVersion actualVersion = SegmentVersion.fromByte(segmentData.getVersion());
> + assertEquals(
> + format("Segment version mismatch. Expected %s, found %s", version, actualVersion),
> + version, actualVersion);
> + }
> + }
> + }
> +
> + private static Iterable<SegmentData> getSegments(@Nonnull TarFiles tarFiles) {
> + return transform(
> + tarFiles.getSegmentIds(),
> + uuid -> newSegmentData(tarFiles.readSegment(
> + uuid.getMostSignificantBits(),
> + uuid.getLeastSignificantBits())));
> + }
> +}
>
> Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy?rev=1805209&view=auto
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy (added)
> +++ jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy Wed Aug 16 15:26:29 2017
> @@ -0,0 +1,40 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + *
> + */
> +
> +import org.apache.jackrabbit.oak.segment.SegmentNodeBuilder
> +import org.apache.jackrabbit.oak.spi.commit.EmptyHook
> +import org.apache.jackrabbit.oak.spi.commit.CommitInfo
> +
> +void addNodes(SegmentNodeBuilder builder, int count, int depth) {
> + if (depth > 0) {
> + for (int c = 0; c < count; c++) {
> + builder.setProperty(
> + "property-name-" + depth + "-" + c,
> + "property-value-" + depth + "-" + c)
> + addNodes(
> + builder.setChildNode("node-" + depth + "-" + c),
> + count,
> + depth - 1)
> + }
> + }
> +}
> +
> +nodeStore = session.store
> +builder = nodeStore.getRoot().builder()
> +addNodes(builder, 10, 5)
> +nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
>
>
Re: svn commit: r1805209 - in /jackrabbit/oak/trunk/oak-segment-tar:
./ src/main/java/org/apache/jackrabbit/oak/segment/file/ src/main/java/org/apache/jackrabbit/oak/segment/file/tar/
src/test/java/org/apache/jackrabbit/oak/segment/upgrade/ src/test/upgrad...
Posted by Francesco Mari <ma...@gmail.com>.
Instead of creating IOMonitor.NULL, you could instantiate a new
IOMonitorAdapter when needed. This has already been done many times in
TarFileTest and TarWriterTest.
On Wed, Aug 16, 2017 at 5:26 PM, <md...@apache.org> wrote:
> Author: mduerig
> Date: Wed Aug 16 15:26:29 2017
> New Revision: 1805209
>
> URL: http://svn.apache.org/viewvc?rev=1805209&view=rev
> Log:
> OAK-6555: Implement ITs for rolling upgrade
>
> Added:
> jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/
> jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java
> jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/
> jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy
> Modified:
> jackrabbit/oak/trunk/oak-segment-tar/pom.xml
> jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java
> jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java
>
> Modified: jackrabbit/oak/trunk/oak-segment-tar/pom.xml
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/pom.xml?rev=1805209&r1=1805208&r2=1805209&view=diff
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-segment-tar/pom.xml (original)
> +++ jackrabbit/oak/trunk/oak-segment-tar/pom.xml Wed Aug 16 15:26:29 2017
> @@ -87,6 +87,40 @@
> <redirectTestOutputToFile>true</redirectTestOutputToFile>
> </configuration>
> </plugin>
> + <plugin>
> + <groupId>org.apache.maven.plugins</groupId>
> + <artifactId>maven-dependency-plugin</artifactId>
> + <executions>
> + <execution>
> + <phase>pre-integration-test</phase>
> + <goals><goal>copy</goal></goals>
> + <configuration>
> + <artifact>org.apache.jackrabbit:oak-run:1.6.1</artifact>
> + <outputDirectory>${project.build.directory}/upgrade-it</outputDirectory>
> + <stripVersion>true</stripVersion>
> + </configuration>
> + </execution>
> + </executions>
> + </plugin>
> + <plugin>
> + <groupId>org.apache.maven.plugins</groupId>
> + <artifactId>maven-resources-plugin</artifactId>
> + <executions>
> + <execution>
> + <phase>pre-integration-test</phase>
> + <goals><goal>copy-resources</goal></goals>
> + <configuration>
> + <outputDirectory>${project.build.directory}/upgrade-it</outputDirectory>
> + <resources>
> + <resource>
> + <directory>src/test/upgrade-it-scripts</directory>
> + <filtering>false</filtering>
> + </resource>
> + </resources>
> + </configuration>
> + </execution>
> + </executions>
> + </plugin>
> </plugins>
> </build>
>
>
> Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java?rev=1805209&r1=1805208&r2=1805209&view=diff
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java (original)
> +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ManifestChecker.java Wed Aug 16 15:26:29 2017
> @@ -22,9 +22,9 @@ import static com.google.common.base.Pre
> import java.io.File;
> import java.io.IOException;
>
> -class ManifestChecker {
> +public class ManifestChecker {
>
> - static ManifestChecker newManifestChecker(File path, boolean shouldExist, int minStoreVersion, int maxStoreVersion) {
> + public static ManifestChecker newManifestChecker(File path, boolean shouldExist, int minStoreVersion, int maxStoreVersion) {
> checkArgument(path != null, "path");
> checkArgument(minStoreVersion > 0, "minStoreVersion");
> checkArgument(maxStoreVersion > 0, "maxStoreVersion");
> @@ -52,7 +52,7 @@ class ManifestChecker {
> updateManifest(manifest);
> }
>
> - void checkManifest() throws IOException, InvalidFileStoreVersionException {
> + public void checkManifest() throws IOException, InvalidFileStoreVersionException {
> checkManifest(openManifest());
> }
>
>
> Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java?rev=1805209&r1=1805208&r2=1805209&view=diff
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java (original)
> +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java Wed Aug 16 15:26:29 2017
> @@ -26,6 +26,16 @@ import java.io.File;
> public interface IOMonitor {
>
> /**
> + * A trivial instance of {@code IOMonitor} that does nothing.
> + */
> + IOMonitor NULL = new IOMonitor(){
> + @Override public void beforeSegmentRead(File file, long msb, long lsb, int length) {}
> + @Override public void afterSegmentRead(File file, long msb, long lsb, int length, long elapsed) {}
> + @Override public void beforeSegmentWrite(File file, long msb, long lsb, int length) {}
> + @Override public void afterSegmentWrite(File file, long msb, long lsb, int length, long elapsed) {}
> + };
> +
> + /**
> * Called before a segment is read from the file system.
> *
> * @param file File containing the segment.
>
> Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java?rev=1805209&view=auto
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java (added)
> +++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java Wed Aug 16 15:26:29 2017
> @@ -0,0 +1,138 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + *
> + */
> +
> +package org.apache.jackrabbit.oak.segment.upgrade;
> +
> +import static com.google.common.collect.Iterables.transform;
> +import static java.lang.String.format;
> +import static java.util.concurrent.TimeUnit.MINUTES;
> +import static org.apache.jackrabbit.oak.segment.SegmentVersion.V_12;
> +import static org.apache.jackrabbit.oak.segment.SegmentVersion.V_13;
> +import static org.apache.jackrabbit.oak.segment.data.SegmentData.newSegmentData;
> +import static org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder;
> +import static org.apache.jackrabbit.oak.segment.file.ManifestChecker.newManifestChecker;
> +import static org.junit.Assert.assertEquals;
> +import static org.junit.Assert.assertTrue;
> +import static org.junit.Assert.fail;
> +
> +import java.io.File;
> +import java.io.IOException;
> +import java.lang.ProcessBuilder.Redirect;
> +
> +import javax.annotation.Nonnull;
> +
> +import org.apache.jackrabbit.oak.segment.SegmentVersion;
> +import org.apache.jackrabbit.oak.segment.data.SegmentData;
> +import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
> +import org.apache.jackrabbit.oak.segment.file.tar.IOMonitor;
> +import org.apache.jackrabbit.oak.segment.file.tar.TarFiles;
> +import org.apache.jackrabbit.oak.segment.tool.Compact;
> +import org.junit.Before;
> +import org.junit.Rule;
> +import org.junit.Test;
> +import org.junit.rules.TemporaryFolder;
> +
> +public class UpgradeIT {
> +
> + private final File upgradeItHome = new File("target/upgrade-it");
> +
> + @Rule
> + public TemporaryFolder fileStoreHome = new TemporaryFolder(upgradeItHome);
> +
> + /**
> + * Launch a groovy script in an Oak 1.6. console to initialise the upgrade
> + * source. See pom.xml for how these files are placed under target/upgrade-it.
> + */
> + @Before
> + public void setup() throws IOException, InterruptedException {
> + Process oakConsole = new ProcessBuilder(
> + "java", "-jar", "oak-run.jar",
> + "console", fileStoreHome.getRoot().getAbsolutePath(), "--read-write",
> + ":load create16store.groovy")
> + .directory(upgradeItHome)
> + .redirectError(Redirect.INHERIT)
> + .redirectOutput(Redirect.INHERIT)
> + .redirectInput(Redirect.INHERIT)
> + .start();
> +
> + assertTrue(
> + "Timeout while creating the source repository",
> + oakConsole.waitFor(2, MINUTES));
> + }
> +
> + @Test
> + public void openUpgradesStore() throws IOException, InvalidFileStoreVersionException {
> + checkStoreVersion(1);
> + fileStoreBuilder(fileStoreHome.getRoot())
> + .build()
> + .close();
> + checkStoreVersion(2);
> + }
> +
> + @Test
> + public void openReadonlyDoesNotUpgradeStore() throws IOException, InvalidFileStoreVersionException {
> + checkStoreVersion(1);
> + fileStoreBuilder(fileStoreHome.getRoot())
> + .buildReadOnly()
> + .close();
> + checkStoreVersion(1);
> + }
> +
> + @Test
> + public void offRCUpgradesSegments() throws IOException, InvalidFileStoreVersionException {
> + checkSegmentVersion(V_12);
> + checkStoreVersion(1);
> + Compact.builder()
> + .withPath(fileStoreHome.getRoot())
> + .withMmap(true)
> + .build()
> + .run();
> + checkStoreVersion(2);
> + checkSegmentVersion(V_13);
> + }
> +
> + private void checkStoreVersion(int version) throws IOException, InvalidFileStoreVersionException {
> + newManifestChecker(new File(fileStoreHome.getRoot(), "/manifest"),
> + true, version, version).checkManifest();
> + }
> +
> + private void checkSegmentVersion(@Nonnull SegmentVersion version) throws IOException {
> + try (TarFiles tarFiles = TarFiles.builder()
> + .withDirectory(fileStoreHome.getRoot())
> + .withTarRecovery((_1, _2, _3) -> fail("Unexpected recovery"))
> + .withIOMonitor(IOMonitor.NULL)
> + .withReadOnly()
> + .build()) {
> +
> + for (SegmentData segmentData : getSegments(tarFiles)) {
> + SegmentVersion actualVersion = SegmentVersion.fromByte(segmentData.getVersion());
> + assertEquals(
> + format("Segment version mismatch. Expected %s, found %s", version, actualVersion),
> + version, actualVersion);
> + }
> + }
> + }
> +
> + private static Iterable<SegmentData> getSegments(@Nonnull TarFiles tarFiles) {
> + return transform(
> + tarFiles.getSegmentIds(),
> + uuid -> newSegmentData(tarFiles.readSegment(
> + uuid.getMostSignificantBits(),
> + uuid.getLeastSignificantBits())));
> + }
> +}
>
> Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy?rev=1805209&view=auto
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy (added)
> +++ jackrabbit/oak/trunk/oak-segment-tar/src/test/upgrade-it-scripts/create16store.groovy Wed Aug 16 15:26:29 2017
> @@ -0,0 +1,40 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + *
> + */
> +
> +import org.apache.jackrabbit.oak.segment.SegmentNodeBuilder
> +import org.apache.jackrabbit.oak.spi.commit.EmptyHook
> +import org.apache.jackrabbit.oak.spi.commit.CommitInfo
> +
> +void addNodes(SegmentNodeBuilder builder, int count, int depth) {
> + if (depth > 0) {
> + for (int c = 0; c < count; c++) {
> + builder.setProperty(
> + "property-name-" + depth + "-" + c,
> + "property-value-" + depth + "-" + c)
> + addNodes(
> + builder.setChildNode("node-" + depth + "-" + c),
> + count,
> + depth - 1)
> + }
> + }
> +}
> +
> +nodeStore = session.store
> +builder = nodeStore.getRoot().builder()
> +addNodes(builder, 10, 5)
> +nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
>
>