You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2011/06/22 13:28:06 UTC
svn commit: r1138407 - in /lucene/dev/branches/branch_3x: ./ lucene/
lucene/backwards/ lucene/backwards/src/test-framework/
lucene/backwards/src/test/ solr/
solr/src/common/org/apache/solr/common/params/
solr/src/java/org/apache/solr/core/ solr/src/jav...
Author: shalin
Date: Wed Jun 22 11:28:05 2011
New Revision: 1138407
URL: http://svn.apache.org/viewvc?rev=1138407&view=rev
Log:
SOLR-2610 -- Add an option to delete index through CoreAdmin UNLOAD action
Modified:
lucene/dev/branches/branch_3x/ (props changed)
lucene/dev/branches/branch_3x/lucene/ (props changed)
lucene/dev/branches/branch_3x/lucene/backwards/ (props changed)
lucene/dev/branches/branch_3x/lucene/backwards/src/test/ (props changed)
lucene/dev/branches/branch_3x/lucene/backwards/src/test-framework/ (props changed)
lucene/dev/branches/branch_3x/solr/ (props changed)
lucene/dev/branches/branch_3x/solr/CHANGES.txt
lucene/dev/branches/branch_3x/solr/src/common/org/apache/solr/common/params/CoreAdminParams.java
lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/core/CloseHook.java
lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/core/SolrCore.java
lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/handler/ReplicationHandler.java
lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
lucene/dev/branches/branch_3x/solr/src/solrj/org/apache/solr/client/solrj/request/CoreAdminRequest.java
lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java
lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/SolrCoreTest.java
Modified: lucene/dev/branches/branch_3x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/CHANGES.txt?rev=1138407&r1=1138406&r2=1138407&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/solr/CHANGES.txt Wed Jun 22 11:28:05 2011
@@ -27,6 +27,12 @@ on how to get started.
================== 3.3.0 ==================
+Upgrading from Solr 3.2.0
+----------------------
+The SolrCore's CloseHook API has been changed in a backward-incompatible way.
+Any custom components which use the SolrCore.addCloseHook method will need to
+be modified accordingly.
+
New Features
----------------------
@@ -52,6 +58,8 @@ New Features
* SOLR-1331: Added a srcCore parameter to CoreAdminHandler's mergeindexes action
to merge one or more cores' indexes to a target core (shalin)
+* SOLR-2610 -- Add an option to delete index through CoreAdmin UNLOAD action (shalin)
+
Optimizations
----------------------
Modified: lucene/dev/branches/branch_3x/solr/src/common/org/apache/solr/common/params/CoreAdminParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/common/org/apache/solr/common/params/CoreAdminParams.java?rev=1138407&r1=1138406&r2=1138407&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/common/org/apache/solr/common/params/CoreAdminParams.java (original)
+++ lucene/dev/branches/branch_3x/solr/src/common/org/apache/solr/common/params/CoreAdminParams.java Wed Jun 22 11:28:05 2011
@@ -69,6 +69,9 @@ public interface CoreAdminParams
/** The shard id in solr cloud */
public final static String SHARD = "shard";
+ /** If you unload a core, delete the index too */
+ public final static String DELETE_INDEX = "deleteIndex";
+
public enum CoreAdminAction {
STATUS,
LOAD,
Modified: lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/core/CloseHook.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/core/CloseHook.java?rev=1138407&r1=1138406&r2=1138407&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/core/CloseHook.java (original)
+++ lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/core/CloseHook.java Wed Jun 22 11:28:05 2011
@@ -18,27 +18,40 @@ package org.apache.solr.core;
/**
- * Interface to request notification when the core is closed.
- *<p/>
+ * Used to request notification when the core is closed.
+ * <p/>
* Call {@link org.apache.solr.core.SolrCore#addCloseHook(org.apache.solr.core.CloseHook)} during the {@link org.apache.solr.util.plugin.SolrCoreAware#inform(SolrCore)} method to
* add a close hook to your object.
* <p/>
- * The close hook can be useful for releasing objects related to the request handler (for instance, if you have a JDBC DataSource or something like that)
- *
- *
- */
+ * The close hook can be useful for releasing objects related to the request handler (for instance, if you have a JDBC DataSource or something like that)
+ */
+
+public abstract class CloseHook {
+
+ /**
+ * Method called when the given SolrCore object is closing / shutting down but before the update handler and
+ * searcher(s) are actually closed
+ * <br />
+ * <b>Important:</b> Keep the method implementation as short as possible. If it were to use any heavy i/o , network connections -
+ * it might be a better idea to launch in a separate Thread so as to not to block the process of
+ * shutting down a given SolrCore instance.
+ *
+ * @param core SolrCore object that is shutting down / closing
+ */
+ public abstract void preClose(SolrCore core);
- public interface CloseHook {
-
- /**
- * Method called when the given SolrCore object is closing / shutting down.
- * <br />
- * <b>Important:</b> Keep the method implementation as short as possible. If it were to use any heavy i/o , network connections -
- * it might be a better idea to launch in a separate Thread so as to not to block the process of
- * shutting down a given SolrCore instance.
- *
- *
- * @param core SolrCore object that is shutting down / closing
- */
- void close( SolrCore core );
- }
+ /**
+ * Method called when the given SolrCore object has been shut down and update handlers and searchers are closed
+ * <br/>
+ * Use this method for post-close clean up operations e.g. deleting the index from disk.
+ * <br/>
+ * <b>The core's passed to the method is already closed and therefore, it's update handler or searcher should *NOT* be used</b>
+ *
+ * <b>Important:</b> Keep the method implementation as short as possible. If it were to use any heavy i/o , network connections -
+ * it might be a better idea to launch in a separate Thread so as to not to block the process of
+ * shutting down a given SolrCore instance.
+ *
+ * @param core
+ */
+ public abstract void postClose(SolrCore core);
+}
Modified: lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/core/SolrCore.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/core/SolrCore.java?rev=1138407&r1=1138406&r2=1138407&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/core/SolrCore.java Wed Jun 22 11:28:05 2011
@@ -692,7 +692,7 @@ public final class SolrCore implements S
if( closeHooks != null ) {
for( CloseHook hook : closeHooks ) {
try {
- hook.close( this );
+ hook.preClose( this );
} catch (Throwable e) {
SolrException.log(log, e);
}
@@ -731,7 +731,15 @@ public final class SolrCore implements S
SolrException.log(log,e);
}
-
+ if( closeHooks != null ) {
+ for( CloseHook hook : closeHooks ) {
+ try {
+ hook.postClose( this );
+ } catch (Throwable e) {
+ SolrException.log(log, e);
+ }
+ }
+ }
}
/** Current core usage count. */
Modified: lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/handler/ReplicationHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/handler/ReplicationHandler.java?rev=1138407&r1=1138406&r2=1138407&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/handler/ReplicationHandler.java (original)
+++ lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/handler/ReplicationHandler.java Wed Jun 22 11:28:05 2011
@@ -889,11 +889,15 @@ public class ReplicationHandler extends
*/
private void registerCloseHook() {
core.addCloseHook(new CloseHook() {
- public void close(SolrCore core) {
+ @Override
+ public void preClose(SolrCore core) {
if (snapPuller != null) {
snapPuller.destroy();
}
}
+
+ @Override
+ public void postClose(SolrCore core) {}
});
}
Modified: lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java?rev=1138407&r1=1138406&r2=1138407&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java (original)
+++ lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java Wed Jun 22 11:28:05 2011
@@ -26,10 +26,7 @@ import org.apache.solr.common.params.Sol
import org.apache.solr.common.params.UpdateParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.core.CoreDescriptor;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.core.DirectoryFactory;
+import org.apache.solr.core.*;
import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.LocalSolrQueryRequest;
@@ -39,6 +36,8 @@ import org.apache.solr.util.RefCounted;
import org.apache.solr.update.MergeIndexesCommand;
import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.apache.solr.update.processor.UpdateRequestProcessorChain;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
@@ -49,6 +48,7 @@ import java.util.Date;
* @since solr 1.3
*/
public class CoreAdminHandler extends RequestHandlerBase {
+ protected static Logger log = LoggerFactory.getLogger(CoreAdminHandler.class);
protected final CoreContainer coreContainer;
public CoreAdminHandler() {
@@ -371,6 +371,23 @@ public class CoreAdminHandler extends Re
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"No such core exists '"+cname+"'");
}
+ if (params.getBool(CoreAdminParams.DELETE_INDEX, false)) {
+ core.addCloseHook(new CloseHook() {
+ @Override
+ public void preClose(SolrCore core) {}
+
+ @Override
+ public void postClose(SolrCore core) {
+ File dataDir = new File(core.getIndexDir());
+ for (File file : dataDir.listFiles()) {
+ if (!file.delete()) {
+ log.error(file.getAbsolutePath() + " could not be deleted on core unload");
+ }
+ }
+ if (!dataDir.delete()) log.error(dataDir.getAbsolutePath() + " could not be deleted on core unload");
+ }
+ });
+ }
core.close();
return coreContainer.isPersistent();
Modified: lucene/dev/branches/branch_3x/solr/src/solrj/org/apache/solr/client/solrj/request/CoreAdminRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/solrj/org/apache/solr/client/solrj/request/CoreAdminRequest.java?rev=1138407&r1=1138406&r2=1138407&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/solrj/org/apache/solr/client/solrj/request/CoreAdminRequest.java (original)
+++ lucene/dev/branches/branch_3x/solr/src/solrj/org/apache/solr/client/solrj/request/CoreAdminRequest.java Wed Jun 22 11:28:05 2011
@@ -163,6 +163,30 @@ public class CoreAdminRequest extends So
}
}
+ public static class Unload extends CoreAdminRequest {
+ protected boolean deleteIndex;
+
+ public Unload(boolean deleteIndex) {
+ action = CoreAdminAction.UNLOAD;
+ this.deleteIndex = deleteIndex;
+ }
+
+ public boolean isDeleteIndex() {
+ return deleteIndex;
+ }
+
+ public void setDeleteIndex(boolean deleteIndex) {
+ this.deleteIndex = deleteIndex;
+ }
+
+ @Override
+ public SolrParams getParams() {
+ ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
+ params.set(CoreAdminParams.DELETE_INDEX, deleteIndex);
+ return params;
+ }
+ }
+
public CoreAdminRequest()
{
super( METHOD.GET, "/admin/cores" );
@@ -244,11 +268,15 @@ public class CoreAdminRequest extends So
public static CoreAdminResponse unloadCore( String name, SolrServer server ) throws SolrServerException, IOException
{
- CoreAdminRequest req = new CoreAdminRequest();
+ return unloadCore(name, false, server);
+ }
+
+ public static CoreAdminResponse unloadCore( String name, boolean deleteIndex, SolrServer server ) throws SolrServerException, IOException
+ {
+ Unload req = new Unload(deleteIndex);
req.setCoreName( name );
- req.setAction( CoreAdminAction.UNLOAD );
return req.process( server );
- }
+ }
public static CoreAdminResponse renameCore(String coreName, String newName, SolrServer server ) throws SolrServerException, IOException
{
Modified: lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java?rev=1138407&r1=1138406&r2=1138407&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java (original)
+++ lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java Wed Jun 22 11:28:05 2011
@@ -23,10 +23,13 @@ import org.apache.solr.client.solrj.requ
import org.apache.solr.client.solrj.request.UpdateRequest.ACTION;
import org.apache.solr.client.solrj.response.CoreAdminResponse;
import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.util.ExternalPaths;
+import java.io.File;
+
/**
* @version $Id$
@@ -150,5 +153,13 @@ public abstract class MultiCoreExampleTe
}
catch( Exception ex ) {}
assertEquals( 1, getSolrCore("corefoo").query( new SolrQuery( "id:BBB" ) ).getResults().size() );
+
+ NamedList<Object> response = getSolrCore("corefoo").query(new SolrQuery().setQueryType("/admin/system")).getResponse();
+ NamedList<Object> coreInfo = (NamedList<Object>) response.get("core");
+ String indexDir = (String) ((NamedList<Object>) coreInfo.get("directory")).get("index");
+ // test delete index on core
+ CoreAdminRequest.unloadCore("corefoo", true, coreadmin);
+ File dir = new File(indexDir);
+ assertFalse("Index directory exists after core unload with deleteIndex=true", dir.exists());
}
}
Modified: lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/SolrCoreTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/SolrCoreTest.java?rev=1138407&r1=1138406&r2=1138407&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/SolrCoreTest.java (original)
+++ lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/SolrCoreTest.java Wed Jun 22 11:28:05 2011
@@ -207,9 +207,13 @@ class ClosingRequestHandler extends Empt
public void inform(SolrCore core) {
core.addCloseHook( new CloseHook() {
- public void close(SolrCore core) {
+ @Override
+ public void preClose(SolrCore core) {
closed = true;
}
+
+ @Override
+ public void postClose(SolrCore core) {}
});
}
}