Author: reschke
Date: Mon Feb 16 13:55:37 2015
New Revision: 1660121
URL: http://svn.apache.org/r1660121
Log:
OAK-2506 - port RDB support back to Oak 1.0
Part 2: re-add RDBBlobStoreTest, wire RDBDocumentStore support into DocumentMK
builder, add RB specific build profiles
Added:
jackrabbit/oak/branches/1.0/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java
(with props)
Modified:
jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
jackrabbit/oak/branches/1.0/oak-parent/pom.xml
Modified:
jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java?rev=1660121&r1=1660120&r2=1660121&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
(original)
+++
jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
Mon Feb 16 13:55:37 2015
@@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import javax.sql.DataSource;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
@@ -47,6 +48,9 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport;
import org.apache.jackrabbit.oak.plugins.document.persistentCache.CacheType;
import
org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCache;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions;
import org.apache.jackrabbit.oak.plugins.document.util.StringValue;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore;
@@ -554,6 +558,34 @@ public class DocumentMK implements Micro
}
/**
+ * Sets a {@link DataSource} to use for the RDB document and blob
+ * stores.
+ *
+ * @return this
+ */
+ public Builder setRDBConnection(DataSource ds) {
+ this.documentStore = new RDBDocumentStore(ds, this);
+ if(this.blobStore == null) {
+ this.blobStore = new RDBBlobStore(ds);
+ }
+ return this;
+ }
+
+ /**
+ * Sets a {@link DataSource} to use for the RDB document and blob
+ * stores, including {@link RDBOptions}.
+ *
+ * @return this
+ */
+ public Builder setRDBConnection(DataSource ds, RDBOptions options) {
+ this.documentStore = new RDBDocumentStore(ds, this, options);
+ if(this.blobStore == null) {
+ this.blobStore = new RDBBlobStore(ds, options);
+ }
+ return this;
+ }
+
+ /**
* Sets the persistent cache option.
*
* @return this
@@ -563,6 +595,18 @@ public class DocumentMK implements Micro
return this;
}
+ /**
+ * Sets a {@link DataSource}s to use for the RDB document and blob
+ * stores.
+ *
+ * @return this
+ */
+ public Builder setRDBConnection(DataSource documentStoreDataSource,
DataSource blobStoreDataSource) {
+ this.documentStore = new RDBDocumentStore(documentStoreDataSource,
this);
+ this.blobStore = new RDBBlobStore(blobStoreDataSource);
+ return this;
+ }
+
/**
* Use the timing document store wrapper.
*
Added:
jackrabbit/oak/branches/1.0/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java?rev=1660121&view=auto
==============================================================================
---
jackrabbit/oak/branches/1.0/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java
(added)
+++
jackrabbit/oak/branches/1.0/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java
Mon Feb 16 13:55:37 2015
@@ -0,0 +1,126 @@
+/*
+ * 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.plugins.document.blob;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStoreFriend;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions;
+import org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Tests the RDBBlobStore implementation.
+ */
+public class RDBBlobStoreTest extends AbstractBlobStoreTest {
+
+ private RDBBlobStore blobStore;
+
+ private static final String URL = System.getProperty("rdb.jdbc-url",
"jdbc:h2:mem:oakblobs");
+
+ private static final String USERNAME = System.getProperty("rdb.jdbc-user",
"sa");
+
+ private static final String PASSWD = System.getProperty("rdb.jdbc-passwd",
"");
+
+ private static final Logger LOG =
LoggerFactory.getLogger(RDBBlobStoreTest.class);
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ blobStore = new RDBBlobStore(RDBDataSourceFactory.forJdbcUrl(URL,
USERNAME, PASSWD), new
RDBOptions().tablePrefix("test").dropTablesOnClose(true));
+ blobStore.setBlockSize(128);
+ blobStore.setBlockSizeMin(48);
+ this.store = blobStore;
+ empty(blobStore);
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ if (blobStore != null) {
+ empty(blobStore);
+ blobStore.close();
+ }
+ }
+
+ private static void empty(RDBBlobStore blobStore) throws Exception {
+ Iterator<String> iter = blobStore.getAllChunkIds(0);
+ List<String> ids = Lists.newArrayList();
+ while (iter.hasNext()) {
+ ids.add(iter.next());
+ }
+ blobStore.deleteChunks(ids, 0);
+ }
+
+ @Test
+ public void testBigBlob() throws Exception {
+ int min = 0;
+ int max = 8 * 1024 * 1024;
+ int test = 0;
+
+ while (max - min >= 2) {
+ test = (max + min) / 2;
+ byte[] data = new byte[test];
+ Random r = new Random(0);
+ r.nextBytes(data);
+ byte[] digest = getDigest(data);
+ try {
+ RDBBlobStoreFriend.storeBlock(blobStore, getDigest(data), 0,
data);
+ byte[] data2 =
RDBBlobStoreFriend.readBlockFromBackend(blobStore, digest);
+ if (!Arrays.equals(data, data2)) {
+ throw new Exception("data mismatch for length " +
data.length);
+ }
+ min = test;
+ } catch (Exception ex) {
+ max = test;
+ }
+ }
+
+ LOG.info("max blob length for " + URL + " was " + test);
+
+ int expected = Math.max(blobStore.getBlockSize(), 2 * 1024 * 1024);
+ assertTrue("expected supported block size is " + expected + ", but
measured: " + test, test >= expected);
+ }
+
+ private byte[] getDigest(byte[] bytes) throws IOException {
+ MessageDigest messageDigest;
+ try {
+ messageDigest = MessageDigest.getInstance("SHA-256");
+ } catch (NoSuchAlgorithmException e) {
+ throw new IOException(e);
+ }
+ messageDigest.update(bytes, 0, bytes.length);
+ return messageDigest.digest();
+ }
+}
Propchange:
jackrabbit/oak/branches/1.0/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/oak/branches/1.0/oak-parent/pom.xml
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-parent/pom.xml?rev=1660121&r1=1660120&r2=1660121&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-parent/pom.xml (original)
+++ jackrabbit/oak/branches/1.0/oak-parent/pom.xml Mon Feb 16 13:55:37 2015
@@ -444,6 +444,88 @@
</build>
</profile>
<profile>
+ <id>rdb-mysql</id>
+ <dependencies>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.34</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
+ <id>rdb-postgres</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>9.3-1101-jdbc4</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
+ <id>rdb-h2</id>
+ <dependencies>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>${h2.version}</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
+ <!-- requires local copy of MS SqlServer JDBC driver deployed to Maven
repo-->
+ <!-- for instance:
+ mvn install:install-file -Dfile=sqljdbc41.jar -Dpackaging=jar\
+ -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.1
+ -->
+ <id>rdb-mssql</id>
+ <dependencies>
+ <dependency>
+ <groupId>com.microsoft.sqlserver</groupId>
+ <artifactId>sqljdbc4</artifactId>
+ <version>4.1</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
+ <!-- requires local copy of Oracle JDBC driver deployed to Maven repo-->
+ <!-- for instance:
+ mvn install:install-file -Dfile=ojdbc6.jar -Dpackaging=jar\
+ -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3.0
+ -->
+ <id>rdb-oracle</id>
+ <dependencies>
+ <dependency>
+ <groupId>com.oracle</groupId>
+ <artifactId>ojdbc6</artifactId>
+ <version>11.2.0.3.0</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
+ <!-- requires local copy of IBM DB2 JDBC drivers deployed to Maven
repo-->
+ <!-- for instance:
+ mvn install:install-file -Dfile=db2jcc4.jar -Dpackaging=jar\
+ -DgroupId=com.ibm.db2 -DartifactId=db2 -Dversion=4.16.53
+ mvn install:install-file -Dfile=db2jcc_license_cu.jar -Dpackaging=jar\
+ -DgroupId=com.ibm.db2 -DartifactId=db2-license -Dversion=4.16.53
+ -->
+ <id>rdb-db2</id>
+ <dependencies>
+ <dependency>
+ <groupId>com.ibm.db2</groupId>
+ <artifactId>db2</artifactId>
+ <version>4.16.53</version>
+ </dependency>
+ <dependency>
+ <groupId>com.ibm.db2</groupId>
+ <artifactId>db2-license</artifactId>
+ <version>4.16.53</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
<id>java8</id>
<activation>
<jdk>[1.8,)</jdk>