mirror of https://github.com/apache/lucene.git
SOLR-708: CoreAdminHandler unload, reload, alias impl
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@687084 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
35a8df10e3
commit
3617c176cd
|
@ -31,13 +31,14 @@ import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction;
|
|||
import org.apache.solr.common.util.ContentStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is experimental and subject to change.
|
||||
* @version $Id: CoreAdminRequest.java 606335 2007-12-21 22:23:39Z ryan $
|
||||
* @since solr 1.3
|
||||
*/
|
||||
public class CoreAdminRequest extends SolrRequest
|
||||
{
|
||||
protected String core = null;
|
||||
protected String other = null;
|
||||
protected CoreAdminParams.CoreAdminAction action = null;
|
||||
|
||||
//a create core request
|
||||
|
@ -87,9 +88,14 @@ public class CoreAdminRequest extends SolrRequest
|
|||
super( METHOD.GET, path );
|
||||
}
|
||||
|
||||
public final void setCoreParam( String v )
|
||||
public final void setCoreName( String coreName )
|
||||
{
|
||||
this.core = v;
|
||||
this.core = coreName;
|
||||
}
|
||||
|
||||
public final void setOtherCoreName( String otherCoreName )
|
||||
{
|
||||
this.other = otherCoreName;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
@ -114,6 +120,9 @@ public class CoreAdminRequest extends SolrRequest
|
|||
ModifiableSolrParams params = new ModifiableSolrParams();
|
||||
params.set( CoreAdminParams.ACTION, action.toString() );
|
||||
params.set( CoreAdminParams.CORE, core );
|
||||
if (other != null) {
|
||||
params.set(CoreAdminParams.OTHER, other);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
|
@ -143,15 +152,41 @@ public class CoreAdminRequest extends SolrRequest
|
|||
public static CoreAdminResponse reloadCore( String name, SolrServer server ) throws SolrServerException, IOException
|
||||
{
|
||||
CoreAdminRequest req = new CoreAdminRequest();
|
||||
req.setCoreParam( name );
|
||||
req.setCoreName( name );
|
||||
req.setAction( CoreAdminAction.RELOAD );
|
||||
return req.process( server );
|
||||
}
|
||||
|
||||
public static CoreAdminResponse unloadCore( String name, SolrServer server ) throws SolrServerException, IOException
|
||||
{
|
||||
CoreAdminRequest req = new CoreAdminRequest();
|
||||
req.setCoreName( name );
|
||||
req.setAction( CoreAdminAction.UNLOAD );
|
||||
return req.process( server );
|
||||
}
|
||||
|
||||
public static CoreAdminResponse renameCore(String coreName, String newName, SolrServer server ) throws SolrServerException, IOException
|
||||
{
|
||||
CoreAdminRequest req = new CoreAdminRequest();
|
||||
req.setCoreName(coreName);
|
||||
req.setOtherCoreName(newName);
|
||||
req.setAction( CoreAdminAction.RENAME );
|
||||
return req.process( server );
|
||||
}
|
||||
|
||||
public static CoreAdminResponse aliasCore(String coreName, String newName, SolrServer server ) throws SolrServerException, IOException
|
||||
{
|
||||
CoreAdminRequest req = new CoreAdminRequest();
|
||||
req.setCoreName(coreName);
|
||||
req.setOtherCoreName(newName);
|
||||
req.setAction( CoreAdminAction.ALIAS );
|
||||
return req.process( server );
|
||||
}
|
||||
|
||||
public static CoreAdminResponse getStatus( String name, SolrServer server ) throws SolrServerException, IOException
|
||||
{
|
||||
CoreAdminRequest req = new CoreAdminRequest();
|
||||
req.setCoreParam( name );
|
||||
req.setCoreName( name );
|
||||
req.setAction( CoreAdminAction.STATUS );
|
||||
return req.process( server );
|
||||
}
|
||||
|
@ -159,7 +194,7 @@ public class CoreAdminRequest extends SolrRequest
|
|||
public static CoreAdminResponse createCore( String name, String instanceDir, SolrServer server ) throws SolrServerException, IOException
|
||||
{
|
||||
CoreAdminRequest.Create req = new CoreAdminRequest.Create();
|
||||
req.setCoreParam( name );
|
||||
req.setCoreName( name );
|
||||
req.setInstanceDir(instanceDir);
|
||||
return req.process( server );
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ 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.core.CoreContainer;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -34,8 +35,9 @@ import org.apache.solr.core.CoreContainer;
|
|||
*/
|
||||
public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
|
||||
{
|
||||
protected static final CoreContainer cores = new CoreContainer();
|
||||
|
||||
// protected static final CoreContainer cores = new CoreContainer();
|
||||
protected static CoreContainer cores;
|
||||
|
||||
@Override public String getSolrHome() { return "../../../example/multicore/"; }
|
||||
|
||||
@Override public String getSchemaFile() { return getSolrHome()+"core0/conf/schema.xml"; }
|
||||
|
@ -43,6 +45,9 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
|
|||
|
||||
@Override public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
cores = h.getCoreContainer();
|
||||
SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
|
||||
cores.setPersistent(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,6 +65,7 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
|
|||
protected abstract SolrServer getSolrCore0();
|
||||
protected abstract SolrServer getSolrCore1();
|
||||
protected abstract SolrServer getSolrAdmin();
|
||||
protected abstract SolrServer getSolrCore(String name);
|
||||
|
||||
|
||||
public void testMultiCore() throws Exception
|
||||
|
@ -114,7 +120,7 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
|
|||
|
||||
assertEquals( 0, getSolrCore1().query( new SolrQuery( "id:AAA" ) ).getResults().size() );
|
||||
assertEquals( 1, getSolrCore1().query( new SolrQuery( "id:BBB" ) ).getResults().size() );
|
||||
|
||||
|
||||
// Now test reloading it should have a newer open time
|
||||
String name = "core0";
|
||||
SolrServer coreadmin = getSolrAdmin();
|
||||
|
@ -125,5 +131,33 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
|
|||
mcr = CoreAdminRequest.getStatus( name, coreadmin );
|
||||
long after = mcr.getStartTime( name ).getTime();
|
||||
assertTrue( "should have more recent time: "+after+","+before, after > before );
|
||||
|
||||
// test alias
|
||||
CoreAdminRequest.aliasCore("core1","corefoo",coreadmin);
|
||||
assertEquals( 1, getSolrCore1().query( new SolrQuery( "id:BBB" ) ).getResults().size() );
|
||||
assertEquals( 1, getSolrCore("corefoo").query( new SolrQuery( "id:BBB" ) ).getResults().size() );
|
||||
|
||||
// test close
|
||||
CoreAdminRequest.unloadCore("corefoo",coreadmin);
|
||||
try {
|
||||
getSolrCore("corefoo").query( new SolrQuery( "id:BBB" ) );
|
||||
fail( "corefoo should be gone" );
|
||||
}
|
||||
catch( Exception ex ) {}
|
||||
// aliased core should still work
|
||||
assertEquals( 1, getSolrCore1().query( new SolrQuery( "id:BBB" ) ).getResults().size() );
|
||||
|
||||
// test move
|
||||
CoreAdminRequest.renameCore("core1","corea",coreadmin);
|
||||
CoreAdminRequest.renameCore("corea","coreb",coreadmin);
|
||||
CoreAdminRequest.renameCore("coreb","corec",coreadmin);
|
||||
CoreAdminRequest.renameCore("corec","cored",coreadmin);
|
||||
CoreAdminRequest.renameCore("cored","corefoo",coreadmin);
|
||||
try {
|
||||
getSolrCore("core1").query( new SolrQuery( "id:BBB" ) );
|
||||
fail( "core1 should be gone" );
|
||||
}
|
||||
catch( Exception ex ) {}
|
||||
assertEquals( 1, getSolrCore("corefoo").query( new SolrQuery( "id:BBB" ) ).getResults().size() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,12 @@ public class MultiCoreEmbeddedTest extends MultiCoreExampleTestBase {
|
|||
return new EmbeddedSolrServer( cores, "core1" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SolrServer getSolrCore(String name)
|
||||
{
|
||||
return new EmbeddedSolrServer( cores, name );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SolrServer getSolrAdmin()
|
||||
{
|
||||
|
|
|
@ -39,11 +39,12 @@ public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {
|
|||
@Override public void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
|
||||
jetty = new JettySolrRunner( context, 0 );
|
||||
jetty.start();
|
||||
port = jetty.getLocalPort();
|
||||
|
||||
|
||||
h.getCoreContainer().setPersistent(false);
|
||||
}
|
||||
|
||||
@Override public void tearDown() throws Exception
|
||||
|
@ -53,6 +54,12 @@ public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected SolrServer getSolrCore(String name)
|
||||
{
|
||||
return createServer(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SolrServer getSolrCore0()
|
||||
{
|
||||
|
|
|
@ -28,13 +28,13 @@ public interface CoreAdminParams
|
|||
|
||||
/** Persistent -- should it save the cores state? **/
|
||||
public final static String PERSISTENT = "persistent";
|
||||
|
||||
/** The name of the the core to swap names with **/
|
||||
public final static String WITH = "with";
|
||||
|
||||
/** If you rename something, what is the new name **/
|
||||
public final static String NAME = "name";
|
||||
|
||||
|
||||
/** Name of the other core in actions involving 2 cores **/
|
||||
public final static String OTHER = "other";
|
||||
|
||||
/** What action **/
|
||||
public final static String ACTION = "action";
|
||||
|
||||
|
@ -53,9 +53,10 @@ public interface CoreAdminParams
|
|||
UNLOAD,
|
||||
RELOAD,
|
||||
CREATE,
|
||||
DROP,
|
||||
PERSIST,
|
||||
SWAP;
|
||||
SWAP,
|
||||
RENAME,
|
||||
ALIAS;
|
||||
|
||||
public static CoreAdminAction get( String p )
|
||||
{
|
||||
|
|
|
@ -505,6 +505,8 @@ public class CoreContainer
|
|||
|
||||
/** Persists the cores config file in a user provided file. */
|
||||
public void persistFile(File file) {
|
||||
log.info("Persisting cores config to " + (file==null ? configFile : file));
|
||||
|
||||
File tmpFile = null;
|
||||
try {
|
||||
// write in temp first
|
||||
|
|
|
@ -642,8 +642,11 @@ public final class SolrCore implements SolrInfoMBean {
|
|||
return refCount.get() <= 0;
|
||||
}
|
||||
|
||||
// this can cause an extra close
|
||||
// protected void finalize() { close(); }
|
||||
protected void finalize() {
|
||||
if (getOpenCount() != 0) {
|
||||
log.severe("REFCOUNT ERROR: unreferenced " + this + " (" + getName() + ") has a reference count of " + getOpenCount());
|
||||
}
|
||||
}
|
||||
|
||||
private List<CloseHook> closeHooks = null;
|
||||
|
||||
|
@ -1431,11 +1434,11 @@ public final class SolrCore implements SolrInfoMBean {
|
|||
}
|
||||
|
||||
public String getSourceId() {
|
||||
return "$Id:$";
|
||||
return "$Id$";
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return "$URL:$";
|
||||
return "$URL$";
|
||||
}
|
||||
|
||||
public URL[] getDocs() {
|
||||
|
|
|
@ -108,12 +108,46 @@ public abstract class CoreAdminHandler extends RequestHandlerBase
|
|||
do_persist = cores.isPersistent();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case RENAME: {
|
||||
String name = params.get(CoreAdminParams.OTHER);
|
||||
if (cname.equals(name)) break;
|
||||
|
||||
SolrCore core = cores.getCore(cname);
|
||||
if (core != null) {
|
||||
do_persist = cores.isPersistent();
|
||||
cores.register(name, core, false);
|
||||
cores.remove(cname);
|
||||
core.close();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ALIAS: {
|
||||
String name = params.get(CoreAdminParams.OTHER);
|
||||
if (cname.equals(name)) break;
|
||||
|
||||
SolrCore core = cores.getCore(cname);
|
||||
if (core != null) {
|
||||
do_persist = cores.isPersistent();
|
||||
cores.register(name, core, false);
|
||||
// no core.close() since each entry in the cores map should increase the ref
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case UNLOAD: {
|
||||
SolrCore core = cores.remove(cname);
|
||||
core.close();
|
||||
do_persist = cores.isPersistent();
|
||||
break;
|
||||
}
|
||||
|
||||
case STATUS: {
|
||||
NamedList<Object> status = new SimpleOrderedMap<Object>();
|
||||
if( cname == null ) {
|
||||
for (SolrCore core : cores.getCores()) {
|
||||
status.add(core.getName(), getCoreStatus( cores, cname ) );
|
||||
for (String name : cores.getCoreNames()) {
|
||||
status.add(name, getCoreStatus( cores, name ) );
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -138,8 +172,8 @@ public abstract class CoreAdminHandler extends RequestHandlerBase
|
|||
|
||||
case SWAP: {
|
||||
do_persist = params.getBool(CoreAdminParams.PERSISTENT, cores.isPersistent());
|
||||
String with = required.get( CoreAdminParams.WITH );
|
||||
cores.swap( cname, with );
|
||||
String other = required.get( CoreAdminParams.OTHER );
|
||||
cores.swap( cname, other );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -156,7 +190,7 @@ public abstract class CoreAdminHandler extends RequestHandlerBase
|
|||
}
|
||||
}
|
||||
|
||||
private static NamedList<Object> getCoreStatus( CoreContainer cores, String cname ) throws IOException
|
||||
private static NamedList<Object> getCoreStatus(CoreContainer cores, String cname ) throws IOException
|
||||
{
|
||||
NamedList<Object> info = new SimpleOrderedMap<Object>();
|
||||
SolrCore core = cores.getCore(cname);
|
||||
|
|
|
@ -796,6 +796,22 @@ public class QueryComponent extends SearchComponent
|
|||
public boolean isLazy() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getBinaryOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getBinaryLength() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public byte[] getBinaryValue() {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
public byte[] getBinaryValue(byte[] result) {
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue