jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1450097 - in /jackrabbit/oak/trunk: oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/ oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/ oak-solr-core/src/test/java/org/apache/jackrabbit...
Date Tue, 26 Feb 2013 09:34:37 GMT
Author: tommaso
Date: Tue Feb 26 09:34:37 2013
New Revision: 1450097

URL: http://svn.apache.org/r1450097
Log:
OAK-655 - added OakSolrUtils#commitByPolicy and OakSolrConfiguration#getCommitPolicy

Added:
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/CommitPolicy.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrConfiguration.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexUpdate.java
    jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java
    jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfiguration.java
    jackrabbit/oak/trunk/oak-solr-remote/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/http/RemoteSolrConfigurationProvider.java

Added: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/CommitPolicy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/CommitPolicy.java?rev=1450097&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/CommitPolicy.java
(added)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/CommitPolicy.java
Tue Feb 26 09:34:37 2013
@@ -0,0 +1,35 @@
+/*
+ * 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.index.solr;
+
+/**
+ * Enum for describing Solr commit policy used in a certain instance
+ */
+public enum CommitPolicy {
+    /**
+     * for default Solr commit
+     */
+    HARD,
+    /**
+     * for Solr soft commit
+     */
+    SOFT,
+    /**
+     * if no commits should be sent (relying on auto(soft)commit on the instance itself)
+     */
+    AUTO
+}

Propchange: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/CommitPolicy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrConfiguration.java?rev=1450097&r1=1450096&r2=1450097&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrConfiguration.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrConfiguration.java
Tue Feb 26 09:34:37 2013
@@ -57,4 +57,11 @@ public interface OakSolrConfiguration {
      */
     public String getFieldForPropertyRestriction(Filter.PropertyRestriction propertyRestriction);
 
+    /**
+     * Provide the commit policy to be used with the underlying Solr instance
+     *
+     * @return a {@link CommitPolicy}
+     */
+    public CommitPolicy getCommitPolicy();
+
 }

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java?rev=1450097&r1=1450096&r2=1450097&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java
Tue Feb 26 09:34:37 2013
@@ -39,8 +39,8 @@ public class OakSolrUtils {
      *
      * @param solrServer the {@link SolrServer} used to communicate with the Solr instance
      * @return <code>true</code> if the given Solr instance is alive and responding
-     * @throws IOException         if any error occurs while trying to communicate with the
Solr instance
-     * @throws SolrServerException
+     * @throws IOException         if any low level IO error occurs
+     * @throws SolrServerException if any error occurs while trying to communicate with the
Solr instance
      */
     public static boolean checkServerAlive(@Nonnull SolrServer solrServer) throws IOException,
SolrServerException {
         return solrServer.ping().getStatus() == 0;
@@ -71,4 +71,29 @@ public class OakSolrUtils {
         ServiceReference serviceReference = ctx.getServiceReference(SolrQueryIndexProvider.class.getName());
         return SolrQueryIndexProvider.class.cast(ctx.getService(serviceReference));
     }
+
+    /**
+     * Trigger a Solr commit on the basis of the given commit policy (e.g. hard, soft, auto)
+     *
+     * @param solrServer   the {@link SolrServer} used to communicate with the Solr instance
+     * @param commitPolicy the {@link CommitPolicy} used to commit changes to a Solr index
+     * @throws IOException         if any low level IO error occurs
+     * @throws SolrServerException if any error occurs while trying to communicate with the
Solr instance
+     */
+    public static void commitByPolicy(SolrServer solrServer, CommitPolicy commitPolicy)
+            throws IOException, SolrServerException {
+        switch (commitPolicy) {
+            case HARD: {
+                solrServer.commit();
+                break;
+            }
+            case SOFT: {
+                solrServer.commit(false, false, true);
+                break;
+            }
+            case AUTO: {
+                break;
+            }
+        }
+    }
 }

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexUpdate.java?rev=1450097&r1=1450096&r2=1450097&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexUpdate.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexUpdate.java
Tue Feb 26 09:34:37 2013
@@ -31,6 +31,7 @@ import org.apache.jackrabbit.oak.api.Com
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrConfiguration;
+import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrUtils;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -98,7 +99,7 @@ public class SolrIndexUpdate implements 
                 NodeState ns = insert.get(p);
                 addSubtreeWriter(solrServer, p, ns);
             }
-            solrServer.commit(false, false, true);
+            OakSolrUtils.commitByPolicy(solrServer,  configuration.getCommitPolicy());
         } catch (IOException e) {
             throw new CommitFailedException(
                     "Failed to update the full text search index", e);

Modified: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java?rev=1450097&r1=1450096&r2=1450097&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java
Tue Feb 26 09:34:37 2013
@@ -90,6 +90,11 @@ public class TestUtils {
             public String getFieldForPropertyRestriction(Filter.PropertyRestriction propertyRestriction)
{
                 return null;
             }
+
+            @Override
+            public CommitPolicy getCommitPolicy() {
+                return CommitPolicy.HARD;
+            }
         };
     }
 

Modified: jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfiguration.java?rev=1450097&r1=1450096&r2=1450097&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfiguration.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfiguration.java
Tue Feb 26 09:34:37 2013
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.plugin
 import javax.jcr.PropertyType;
 
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.index.solr.CommitPolicy;
 import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrConfiguration;
 import org.apache.jackrabbit.oak.spi.query.Filter;
 
@@ -75,4 +76,9 @@ public class EmbeddedSolrConfiguration i
     public String getFieldForPropertyRestriction(Filter.PropertyRestriction propertyRestriction)
{
         return null;
     }
+
+    @Override
+    public CommitPolicy getCommitPolicy() {
+        return CommitPolicy.SOFT;
+    }
 }

Modified: jackrabbit/oak/trunk/oak-solr-remote/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/http/RemoteSolrConfigurationProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-remote/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/http/RemoteSolrConfigurationProvider.java?rev=1450097&r1=1450096&r2=1450097&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-remote/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/http/RemoteSolrConfigurationProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-remote/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/http/RemoteSolrConfigurationProvider.java
Tue Feb 26 09:34:37 2013
@@ -20,6 +20,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.index.solr.CommitPolicy;
 import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrConfiguration;
 import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrConfigurationProvider;
 import org.apache.jackrabbit.oak.spi.query.Filter;
@@ -130,6 +131,11 @@ public class RemoteSolrConfigurationProv
                 public String getFieldForPropertyRestriction(Filter.PropertyRestriction propertyRestriction)
{
                     return null;
                 }
+
+                @Override
+                public CommitPolicy getCommitPolicy() {
+                    return CommitPolicy.SOFT;
+                }
             };
         }
         return oakSolrConfiguration;



Mime
View raw message