mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
[ SEARCH-1752 ] First working draft
This commit is contained in:
+34
-18
@@ -34,6 +34,7 @@ import org.alfresco.solr.tracker.CommitTracker;
|
||||
import org.alfresco.solr.tracker.ContentTracker;
|
||||
import org.alfresco.solr.tracker.MetadataTracker;
|
||||
import org.alfresco.solr.tracker.ModelTracker;
|
||||
import org.alfresco.solr.tracker.SlaveNodeStateProvider;
|
||||
import org.alfresco.solr.tracker.SolrTrackerScheduler;
|
||||
import org.alfresco.solr.tracker.Tracker;
|
||||
import org.alfresco.solr.tracker.TrackerRegistry;
|
||||
@@ -117,6 +118,31 @@ public class SolrCoreLoadListener extends AbstractSolrEventListener
|
||||
scheduler);
|
||||
}
|
||||
|
||||
/*
|
||||
* The shutdown hook needs to be registered regardless we are slave or masters.
|
||||
* This because if we are master all trackers will be scheduled, if we are slave the node state publisher
|
||||
* will be scheduled.
|
||||
*
|
||||
* As consequence of that, regardless the node role, we will always have something to shutdown in the tracker
|
||||
* registry.
|
||||
*/
|
||||
final List<Tracker> trackers = new ArrayList<>();
|
||||
core.addCloseHook(new CloseHook()
|
||||
{
|
||||
@Override
|
||||
public void preClose(SolrCore core)
|
||||
{
|
||||
LOGGER.info("Tracking Subsystem shutdown procedure for core {} has been started.", core.getName());
|
||||
shutdownTrackers(core.getName(), trackers, scheduler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postClose(SolrCore core)
|
||||
{
|
||||
LOGGER.info("Tracking Subsystem shutdown procedure for core {} has been completed.", core.getName());
|
||||
}
|
||||
});
|
||||
|
||||
boolean trackersHaveBeenEnabled = Boolean.parseBoolean(coreProperties.getProperty("enable.alfresco.tracking", "true"));
|
||||
boolean owningCoreIsSlave = isSlaveModeEnabledFor(core);
|
||||
|
||||
@@ -132,6 +158,13 @@ public class SolrCoreLoadListener extends AbstractSolrEventListener
|
||||
if (owningCoreIsSlave)
|
||||
{
|
||||
LOGGER.info("SearchServices Core Trackers have been disabled on core \"{}\" because it is a slave core.", core.getName());
|
||||
|
||||
SlaveNodeStateProvider stateProvider = new SlaveNodeStateProvider(coreProperties, repositoryClient, core.getName(), informationServer);
|
||||
trackerRegistry.register(core.getName(), stateProvider);
|
||||
scheduler.schedule(stateProvider, core.getName(), coreProperties);
|
||||
|
||||
LOGGER.info("SearchServices Slave Node Provider have been created and scheduled for core \"{}\".", core.getName());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -144,7 +177,7 @@ public class SolrCoreLoadListener extends AbstractSolrEventListener
|
||||
admin.getInformationServers().remove(core.getName());
|
||||
}
|
||||
|
||||
final List<Tracker> trackers = createCoreTrackers(core.getName(), trackerRegistry, coreProperties, scheduler, repositoryClient, informationServer);
|
||||
trackers.addAll(createCoreTrackers(core.getName(), trackerRegistry, coreProperties, scheduler, repositoryClient, informationServer));
|
||||
|
||||
CommitTracker commitTracker = new CommitTracker(coreProperties, repositoryClient, core.getName(), informationServer, trackers);
|
||||
trackerRegistry.register(core.getName(), commitTracker);
|
||||
@@ -154,23 +187,6 @@ public class SolrCoreLoadListener extends AbstractSolrEventListener
|
||||
|
||||
//Add the commitTracker to the list of scheduled trackers that can be shutdown
|
||||
trackers.add(commitTracker);
|
||||
|
||||
core.addCloseHook(new CloseHook()
|
||||
{
|
||||
@Override
|
||||
public void preClose(SolrCore core)
|
||||
{
|
||||
LOGGER.info("Tracking Subsystem shutdown procedure for core {} has been started.", core.getName());
|
||||
shutdownTrackers(core.getName(), trackers, scheduler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postClose(SolrCore core)
|
||||
{
|
||||
LOGGER.info("Shutdown procedure for core {} has been completed.", core.getName());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
List<Tracker> createCoreTrackers(String coreName,
|
||||
|
||||
+2
-2
@@ -67,7 +67,7 @@ public class MetadataTracker extends NodeStateProvider implements Tracker
|
||||
public MetadataTracker(Properties p, SOLRAPIClient client, String coreName,
|
||||
InformationServer informationServer)
|
||||
{
|
||||
super(p, client, coreName, informationServer, Tracker.Type.MetaData);
|
||||
super(p, client, coreName, informationServer, Tracker.Type.METADATA);
|
||||
transactionDocsBatchSize = Integer.parseInt(p.getProperty("alfresco.transactionDocsBatchSize", "100"));
|
||||
nodeBatchSize = Integer.parseInt(p.getProperty("alfresco.nodeBatchSize", "10"));
|
||||
threadHandler = new ThreadHandler(p, coreName, "MetadataTracker");
|
||||
@@ -75,7 +75,7 @@ public class MetadataTracker extends NodeStateProvider implements Tracker
|
||||
|
||||
MetadataTracker()
|
||||
{
|
||||
super(Tracker.Type.MetaData);
|
||||
super(Tracker.Type.METADATA);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -103,7 +103,7 @@ public class ModelTracker extends AbstractTracker implements Tracker
|
||||
public ModelTracker(String solrHome, Properties p, SOLRAPIClient client, String coreName,
|
||||
InformationServer informationServer)
|
||||
{
|
||||
super(p, client, coreName, informationServer, Tracker.Type.Model);
|
||||
super(p, client, coreName, informationServer, Tracker.Type.MODEL);
|
||||
String normalSolrHome = SolrResourceLoader.normalizeDir(solrHome);
|
||||
alfrescoModelDir = new File(ConfigUtil.locateProperty("solr.model.dir", normalSolrHome+"alfrescoModels"));
|
||||
log.info("Alfresco Model dir " + alfrescoModelDir);
|
||||
@@ -187,7 +187,7 @@ public class ModelTracker extends AbstractTracker implements Tracker
|
||||
*/
|
||||
ModelTracker()
|
||||
{
|
||||
super(Tracker.Type.Model);
|
||||
super(Tracker.Type.MODEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -25,6 +25,10 @@
|
||||
*/
|
||||
package org.alfresco.solr.tracker;
|
||||
|
||||
import static java.util.Optional.of;
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static org.alfresco.solr.tracker.DocRouterFactory.SHARD_KEY_KEY;
|
||||
|
||||
import org.alfresco.opencmis.dictionary.CMISStrictDictionaryService;
|
||||
import org.alfresco.repo.dictionary.NamespaceDAO;
|
||||
import org.alfresco.repo.index.shard.ShardMethodEnum;
|
||||
@@ -45,10 +49,6 @@ import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
import static java.util.Optional.of;
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static org.alfresco.solr.tracker.DocRouterFactory.SHARD_KEY_KEY;
|
||||
|
||||
/**
|
||||
* Superclass for all components which are able to inform Alfresco about the hosting node state.
|
||||
* This has been introduced in SEARCH-1752 for splitting the dual responsibility of the {@link MetadataTracker}.
|
||||
|
||||
+11
-1
@@ -1,10 +1,15 @@
|
||||
package org.alfresco.solr.tracker;
|
||||
|
||||
import static org.alfresco.solr.tracker.Tracker.Type.NODE_STATE_PUBLISHER;
|
||||
|
||||
import org.alfresco.httpclient.AuthenticationException;
|
||||
import org.alfresco.repo.index.shard.ShardState;
|
||||
import org.alfresco.solr.SolrInformationServer;
|
||||
import org.alfresco.solr.client.SOLRAPIClient;
|
||||
import org.apache.commons.codec.EncoderException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Despite belonging to the Tracker ecosystem, this component is actually a publisher, which periodically informs
|
||||
@@ -21,8 +26,13 @@ import java.io.IOException;
|
||||
* @author Andrea Gazzarini
|
||||
* @since 1.5
|
||||
*/
|
||||
public class SlaveNodeStateProvider extends MetadataTracker
|
||||
public class SlaveNodeStateProvider extends NodeStateProvider
|
||||
{
|
||||
public SlaveNodeStateProvider(Properties coreProperties, SOLRAPIClient repositoryClient, String name, SolrInformationServer informationServer)
|
||||
{
|
||||
super(coreProperties, repositoryClient, name, informationServer, NODE_STATE_PUBLISHER);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doTrack()
|
||||
{
|
||||
|
||||
+16
-11
@@ -76,18 +76,20 @@ public class SolrTrackerScheduler
|
||||
{
|
||||
log.error("Failed to schedule " + jobType + " Job.", e);
|
||||
}
|
||||
|
||||
private String getCron(Properties props, String cronType)
|
||||
{
|
||||
String cron = props.getProperty(cronType);
|
||||
return cron == null ? props.getProperty("alfresco.cron",DEFAULT_CRON) : cron;
|
||||
return cron == null ? props.getProperty("alfresco.cron", DEFAULT_CRON) : cron;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules individual trackers based on the solrcore properties.
|
||||
*
|
||||
* @author Michael Suzuki
|
||||
* @param tracker
|
||||
* @param coreName
|
||||
* @param props
|
||||
* @param tracker the tracker to bo scheduled.
|
||||
* @param coreName the owning core name.
|
||||
* @param props the core properties.
|
||||
*/
|
||||
public void schedule(Tracker tracker, String coreName, Properties props)
|
||||
{
|
||||
@@ -98,27 +100,30 @@ public class SolrTrackerScheduler
|
||||
Trigger trigger;
|
||||
try
|
||||
{
|
||||
String cron = null;
|
||||
String cron;
|
||||
switch (tracker.getType())
|
||||
{
|
||||
case ACL:
|
||||
cron = getCron(props,"alfresco.acl.tracker.cron");
|
||||
break;
|
||||
case Model:
|
||||
case MODEL:
|
||||
cron = getCron(props,"alfresco.model.tracker.cron");
|
||||
break;
|
||||
case Content:
|
||||
case CONTENT:
|
||||
cron = getCron(props,"alfresco.content.tracker.cron");
|
||||
break;
|
||||
case MetaData:
|
||||
case METADATA:
|
||||
cron = getCron(props,"alfresco.metadata.tracker.cron");
|
||||
break;
|
||||
case Cascade:
|
||||
case CASCADE:
|
||||
cron = getCron(props,"alfresco.cascade.tracker.cron");
|
||||
break;
|
||||
case Commit:
|
||||
case COMMIT:
|
||||
cron = getCron(props,"alfresco.commit.tracker.cron");
|
||||
break;
|
||||
case NODE_STATE_PUBLISHER:
|
||||
cron = getCron(props,"alfresco.nodestate.tracker.cron");
|
||||
break;
|
||||
default:
|
||||
cron = props.getProperty("alfresco.cron",DEFAULT_CRON);
|
||||
break;
|
||||
@@ -161,7 +166,7 @@ public class SolrTrackerScheduler
|
||||
* identical to the instance that is passed in. If they are identical then the job is deleted.
|
||||
* Otherwise, another core (of the same name) scheduled this job, so its left alone.
|
||||
*
|
||||
* @param coreName
|
||||
* @param coreName the core name.
|
||||
* @param tracker Specific instance of a tracker
|
||||
*/
|
||||
public void deleteJobForTrackerInstance(String coreName, Tracker tracker)
|
||||
|
||||
Reference in New Issue
Block a user