You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2013/01/08 04:40:37 UTC
svn commit: r1430130 [18/27] - in /lucene/dev/branches/lucene4547: ./
dev-tools/ dev-tools/eclipse/ dev-tools/idea/.idea/libraries/
dev-tools/maven/ dev-tools/maven/solr/
dev-tools/maven/solr/contrib/analysis-extras/
dev-tools/maven/solr/contrib/cluste...
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/cloud/ZkController.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/cloud/ZkController.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/cloud/ZkController.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/cloud/ZkController.java Tue Jan 8 03:40:16 2013
@@ -19,8 +19,11 @@ package org.apache.solr.cloud;
import java.io.File;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.NetworkInterface;
+import java.net.URLEncoder;
+import java.net.UnknownHostException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
@@ -29,9 +32,6 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Future;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -45,6 +45,8 @@ import org.apache.solr.common.SolrExcept
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.DocCollection;
+import org.apache.solr.common.cloud.DocRouter;
+import org.apache.solr.common.cloud.ImplicitDocRouter;
import org.apache.solr.common.cloud.OnReconnect;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkCmdExecutor;
@@ -53,16 +55,14 @@ import org.apache.solr.common.cloud.ZkNo
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.cloud.ZooKeeperException;
import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.util.ExecutorUtil;
-
import org.apache.solr.core.Config;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.component.ShardHandler;
import org.apache.solr.update.UpdateLog;
+import org.apache.solr.update.UpdateShardHandler;
import org.apache.solr.util.DOMUtil;
-import org.apache.solr.util.DefaultSolrThreadFactory;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.NoNodeException;
@@ -97,17 +97,11 @@ public final class ZkController {
private final DistributedQueue overseerJobQueue;
private final DistributedQueue overseerCollectionQueue;
- // package private for tests
-
- static final String CONFIGS_ZKNODE = "/configs";
+ public static final String CONFIGS_ZKNODE = "/configs";
public final static String COLLECTION_PARAM_PREFIX="collection.";
public final static String CONFIGNAME_PROP="configName";
- private ThreadPoolExecutor cmdDistribExecutor = new ThreadPoolExecutor(
- 0, Integer.MAX_VALUE, 5, TimeUnit.SECONDS,
- new SynchronousQueue<Runnable>(), new DefaultSolrThreadFactory(
- "cmdDistribExecutor"));
private final Map<String, ElectionContext> electionContexts = Collections.synchronizedMap(new HashMap<String, ElectionContext>());
@@ -140,29 +134,43 @@ public final class ZkController {
private int clientTimeout;
+ private volatile boolean isClosed;
+
+ private UpdateShardHandler updateShardHandler;
+
public ZkController(final CoreContainer cc, String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout, String localHost, String locaHostPort,
- String localHostContext, String leaderVoteWait, final CurrentCoreDescriptorProvider registerOnReconnect) throws InterruptedException,
+ String localHostContext, String leaderVoteWait, int distribUpdateConnTimeout, int distribUpdateSoTimeout, final CurrentCoreDescriptorProvider registerOnReconnect) throws InterruptedException,
TimeoutException, IOException {
if (cc == null) throw new IllegalArgumentException("CoreContainer cannot be null.");
this.cc = cc;
- if (localHostContext.contains("/")) {
- throw new IllegalArgumentException("localHostContext ("
- + localHostContext + ") should not contain a /");
- }
+
+ // be forgiving and strip this off leading/trailing slashes
+ // this allows us to support users specifying hostContext="/" in
+ // solr.xml to indicate the root context, instead of hostContext=""
+ // which means the default of "solr"
+ localHostContext = trimLeadingAndTrailingSlashes(localHostContext);
+
+ updateShardHandler = new UpdateShardHandler(distribUpdateConnTimeout, distribUpdateSoTimeout);
this.zkServerAddress = zkServerAddress;
this.localHostPort = locaHostPort;
this.localHostContext = localHostContext;
this.localHost = getHostAddress(localHost);
+ this.baseURL = this.localHost + ":" + this.localHostPort +
+ (this.localHostContext.isEmpty() ? "" : ("/" + this.localHostContext));
+
this.hostName = getHostNameFromAddress(this.localHost);
- this.nodeName = this.hostName + ':' + this.localHostPort + '_' + this.localHostContext;
- this.baseURL = this.localHost + ":" + this.localHostPort + "/" + this.localHostContext;
+ this.nodeName = generateNodeName(this.hostName,
+ this.localHostPort,
+ this.localHostContext);
+
this.leaderVoteWait = leaderVoteWait;
this.clientTimeout = zkClientTimeout;
zkClient = new SolrZkClient(zkServerAddress, zkClientTimeout, zkClientConnectTimeout,
// on reconnect, reload cloud info
new OnReconnect() {
+ @Override
public void command() {
try {
markAllAsNotLeader(registerOnReconnect);
@@ -225,7 +233,7 @@ public final class ZkController {
this.overseerJobQueue = Overseer.getInQueue(zkClient);
this.overseerCollectionQueue = Overseer.getCollectionQueue(zkClient);
- cmdExecutor = new ZkCmdExecutor();
+ cmdExecutor = new ZkCmdExecutor(zkClientTimeout);
leaderElector = new LeaderElector(zkClient);
zkStateReader = new ZkStateReader(zkClient);
@@ -240,6 +248,7 @@ public final class ZkController {
final CurrentCoreDescriptorProvider registerOnReconnect, boolean updateLastPublished) {
List<CoreDescriptor> descriptors = registerOnReconnect
.getCurrentDescriptors();
+ if (isClosed) return;
if (descriptors != null) {
// before registering as live, make sure everyone is in a
// down state
@@ -250,6 +259,9 @@ public final class ZkController {
descriptor.getCloudDescriptor().isLeader = false;
publish(descriptor, ZkStateReader.DOWN, updateLastPublished);
} catch (Exception e) {
+ if (isClosed) {
+ return;
+ }
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
@@ -262,10 +274,39 @@ public final class ZkController {
continue;
}
}
+
+ // if it looks like we are going to be the leader, we don't
+ // want to wait for the following stuff
+ CloudDescriptor cloudDesc = descriptor.getCloudDescriptor();
+ String collection = cloudDesc.getCollectionName();
+ String slice = cloudDesc.getShardId();
+ try {
+
+ int children = zkStateReader
+ .getZkClient()
+ .getChildren(
+ ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection
+ + "/leader_elect/" + slice + "/election", null, true).size();
+ if (children == 0) {
+ return;
+ }
+
+ } catch (NoNodeException e) {
+ return;
+ } catch (InterruptedException e2) {
+ Thread.currentThread().interrupt();
+ } catch (KeeperException e) {
+ log.warn("", e);
+ Thread.currentThread().interrupt();
+ }
+
try {
waitForLeaderToSeeDownState(descriptor, coreZkNodeName);
} catch (Exception e) {
SolrException.log(log, "", e);
+ if (isClosed) {
+ return;
+ }
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
@@ -291,14 +332,7 @@ public final class ZkController {
* Closes the underlying ZooKeeper client.
*/
public void close() {
-
- if (cmdDistribExecutor != null) {
- try {
- ExecutorUtil.shutdownNowAndAwaitTermination(cmdDistribExecutor);
- } catch (Throwable e) {
- SolrException.log(log, e);
- }
- }
+ this.isClosed = true;
for (ElectionContext context : electionContexts.values()) {
try {
@@ -313,7 +347,20 @@ public final class ZkController {
} catch(Throwable t) {
log.error("Error closing overseer", t);
}
- zkClient.close();
+
+ try {
+ zkClient.close();;
+ } catch(Throwable t) {
+ log.error("Error closing zkClient", t);
+ }
+
+ if (updateShardHandler != null) {
+ try {
+ updateShardHandler.close();
+ } catch(Throwable t) {
+ log.error("Error closing updateShardHandler", t);
+ }
+ }
}
/**
@@ -353,7 +400,12 @@ public final class ZkController {
private String getHostAddress(String host) throws IOException {
if (host == null) {
- String hostaddress = InetAddress.getLocalHost().getHostAddress();
+ String hostaddress;
+ try {
+ hostaddress = InetAddress.getLocalHost().getHostAddress();
+ } catch (UnknownHostException e) {
+ hostaddress = "127.0.0.1"; // cannot resolve system hostname, fall through
+ }
// Re-get the IP again for "127.0.0.1", the other case we trust the hosts
// file is right.
if ("127.0.0.1".equals(hostaddress)) {
@@ -462,6 +514,37 @@ public final class ZkController {
}
+ /**
+ * Validates if the chroot exists in zk (or if it is successfully created). Optionally, if create is set to true this method will create the path
+ * in case it doesn't exist
+ * @return true if the path exists or is created
+ * false if the path doesn't exist and 'create' = false
+ */
+ public static boolean checkChrootPath(String zkHost, boolean create) throws KeeperException, InterruptedException {
+ if(!containsChroot(zkHost)) {
+ return true;
+ }
+ log.info("zkHost includes chroot");
+ String chrootPath = zkHost.substring(zkHost.indexOf("/"), zkHost.length());
+ SolrZkClient tmpClient = new SolrZkClient(zkHost.substring(0, zkHost.indexOf("/")), 60*1000);
+ boolean exists = tmpClient.exists(chrootPath, true);
+ if(!exists && create) {
+ tmpClient.makePath(chrootPath, false, true);
+ exists = true;
+ }
+ tmpClient.close();
+ return exists;
+ }
+
+
+ /**
+ * Validates if zkHost contains a chroot. See http://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#ch_zkSessions
+ */
+ private static boolean containsChroot(String zkHost) {
+ return zkHost.contains("/");
+ }
+
+
public boolean isConnected() {
return zkClient.isConnected();
}
@@ -575,8 +658,8 @@ public final class ZkController {
if (log.isInfoEnabled()) {
- log.info("Register shard - core:" + coreName + " address:"
- + baseUrl + " shardId:" + shardId);
+ log.info("Register replica - core:" + coreName + " address:"
+ + baseUrl + " collection:" + cloudDesc.getCollectionName() + " shard:" + shardId);
}
ZkNodeProps leaderProps = new ZkNodeProps(props);
@@ -595,8 +678,9 @@ public final class ZkController {
// in this case, we want to wait for the leader as long as the leader might
- // wait for a vote, at least
- String leaderUrl = getLeader(cloudDesc, Integer.parseInt(leaderVoteWait) + 1000);
+ // wait for a vote, at least - but also long enough that a large cluster has
+ // time to get its act together
+ String leaderUrl = getLeader(cloudDesc, Integer.parseInt(leaderVoteWait) + 600000);
String ourUrl = ZkCoreNodeProps.getCoreUrl(baseUrl, coreName);
log.info("We are " + ourUrl + " and leader is " + leaderUrl);
@@ -664,7 +748,7 @@ public final class ZkController {
// now wait until our currently cloud state contains the latest leader
String clusterStateLeader = zkStateReader.getLeaderUrl(collection,
- shardId, 30000);
+ shardId, timeoutms);
int tries = 0;
while (!leaderUrl.equals(clusterStateLeader)) {
if (tries == 60) {
@@ -676,7 +760,7 @@ public final class ZkController {
Thread.sleep(1000);
tries++;
clusterStateLeader = zkStateReader.getLeaderUrl(collection, shardId,
- 30000);
+ timeoutms);
leaderUrl = getLeaderProps(collection, cloudDesc.getShardId(), timeoutms)
.getCoreUrl();
}
@@ -889,9 +973,6 @@ public final class ZkController {
try {
Map<String,Object> collectionProps = new HashMap<String,Object>();
- // set defaults
- collectionProps.put(DocCollection.DOC_ROUTER, "compositeId");
-
// TODO: if collection.configName isn't set, and there isn't already a conf in zk, just use that?
String defaultConfigName = System.getProperty(COLLECTION_PARAM_PREFIX+CONFIGNAME_PROP, collection);
@@ -933,6 +1014,21 @@ public final class ZkController {
} else {
getConfName(collection, collectionPath, collectionProps);
}
+
+ if (collectionProps.get(DocCollection.DOC_ROUTER) == null) {
+ Object numShards = collectionProps.get(ZkStateReader.NUM_SHARDS_PROP);
+ if (numShards == null) {
+ numShards = System.getProperty(ZkStateReader.NUM_SHARDS_PROP);
+ }
+ if (numShards == null) {
+ collectionProps.put(DocCollection.DOC_ROUTER, ImplicitDocRouter.NAME);
+ } else {
+ collectionProps.put(DocCollection.DOC_ROUTER, DocRouter.DEFAULT_NAME);
+ }
+ }
+
+ collectionProps.remove(ZkStateReader.NUM_SHARDS_PROP); // we don't put numShards in the collections properties
+
ZkNodeProps zkProps = new ZkNodeProps(collectionProps);
zkClient.makePath(collectionPath, ZkStateReader.toJSON(zkProps), CreateMode.PERSISTENT, null, true);
@@ -1009,7 +1105,7 @@ public final class ZkController {
private String doGetShardIdProcess(String coreName, CloudDescriptor descriptor) {
final String shardZkNodeName = getNodeName() + "_" + coreName;
- int retryCount = 120;
+ int retryCount = 320;
while (retryCount-- > 0) {
final String shardId = zkStateReader.getClusterState().getShardId(
shardZkNodeName);
@@ -1017,7 +1113,7 @@ public final class ZkController {
return shardId;
}
try {
- Thread.sleep(500);
+ Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
@@ -1124,7 +1220,7 @@ public final class ZkController {
HttpSolrServer server = null;
server = new HttpSolrServer(leaderBaseUrl);
server.setConnectionTimeout(45000);
- server.setSoTimeout(45000);
+ server.setSoTimeout(120000);
WaitForState prepCmd = new WaitForState();
prepCmd.setCoreName(leaderCoreName);
prepCmd.setNodeName(getNodeName());
@@ -1239,8 +1335,45 @@ public final class ZkController {
}
// may return null if not in zk mode
- public ThreadPoolExecutor getCmdDistribExecutor() {
- return cmdDistribExecutor;
+ public UpdateShardHandler getUpdateShardHandler() {
+ return updateShardHandler;
}
+ /**
+ * Returns the nodeName that should be used based on the specified properties.
+ *
+ * @param hostName - must not be null or the empty string
+ * @param hostPort - must consist only of digits, must not be null or the empty string
+ * @param hostContext - should not begin or end with a slash (leading/trailin slashes will be ignored), must not be null, may be the empty string to denote the root context
+ * @lucene.experimental
+ * @see SolrZkClient#getBaseUrlForNodeName
+ */
+ static String generateNodeName(final String hostName,
+ final String hostPort,
+ final String hostContext) {
+ try {
+ return hostName + ':' + hostPort + '_' +
+ URLEncoder.encode(trimLeadingAndTrailingSlashes(hostContext), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalStateException("JVM Does not seem to support UTF-8", e);
+ }
+ }
+
+ /**
+ * utilitiy method fro trimming and leading and/or trailing slashes from
+ * it's input. May return the empty string. May return null if and only
+ * if the input is null.
+ */
+ private static String trimLeadingAndTrailingSlashes(final String in) {
+ if (null == in) return in;
+
+ String out = in;
+ if (out.startsWith("/")) {
+ out = out.substring(1);
+ }
+ if (out.endsWith("/")) {
+ out = out.substring(0,out.length()-1);
+ }
+ return out;
+ }
}
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/AbstractSolrEventListener.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/AbstractSolrEventListener.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/AbstractSolrEventListener.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/AbstractSolrEventListener.java Tue Jan 8 03:40:16 2013
@@ -30,10 +30,12 @@ public class AbstractSolrEventListener i
}
protected NamedList args;
+ @Override
public void init(NamedList args) {
this.args = args;
}
+ @Override
public void postCommit() {
throw new UnsupportedOperationException();
}
@@ -43,6 +45,7 @@ public class AbstractSolrEventListener i
throw new UnsupportedOperationException();
}
+ @Override
public void newSearcher(SolrIndexSearcher newSearcher, SolrIndexSearcher currentSearcher) {
throw new UnsupportedOperationException();
}
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java Tue Jan 8 03:40:16 2013
@@ -26,8 +26,10 @@ import java.util.Locale;
import java.util.Map;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext.Context;
import org.apache.lucene.store.NativeFSLockFactory;
import org.apache.lucene.store.NoLockFactory;
+import org.apache.lucene.store.RateLimitedDirectoryWrapper;
import org.apache.lucene.store.SimpleFSLockFactory;
import org.apache.lucene.store.SingleInstanceLockFactory;
import org.apache.solr.common.SolrException;
@@ -47,6 +49,7 @@ public abstract class CachingDirectoryFa
public int refCnt = 1;
public String path;
public boolean doneWithDir = false;
+ @Override
public String toString() {
return "CachedDir<<" + directory.toString() + ";refCount=" + refCnt + ";path=" + path + ";done=" + doneWithDir + ">>";
}
@@ -60,6 +63,16 @@ public abstract class CachingDirectoryFa
protected Map<Directory,CacheValue> byDirectoryCache = new HashMap<Directory,CacheValue>();
protected Map<Directory,List<CloseListener>> closeListeners = new HashMap<Directory,List<CloseListener>>();
+
+ private Double maxWriteMBPerSecFlush;
+
+ private Double maxWriteMBPerSecMerge;
+
+ private Double maxWriteMBPerSecRead;
+
+ private Double maxWriteMBPerSecDefault;
+
+ private boolean closed;
public interface CloseListener {
public void postClose();
@@ -109,6 +122,7 @@ public abstract class CachingDirectoryFa
@Override
public void close() throws IOException {
synchronized (this) {
+ this.closed = true;
for (CacheValue val : byDirectoryCache.values()) {
try {
// if there are still refs out, we have to wait for them
@@ -116,14 +130,15 @@ public abstract class CachingDirectoryFa
while(val.refCnt != 0) {
wait(100);
- if (cnt++ >= 12000) {
+ if (cnt++ >= 1200) {
log.error("Timeout waiting for all directory ref counts to be released");
break;
}
}
assert val.refCnt == 0 : val.refCnt;
- val.directory.close();
+ log.info("Closing directory when closing factory:" + val.path);
+ closeDirectory(val);
} catch (Throwable t) {
SolrException.log(log, "Error closing directory", t);
}
@@ -135,6 +150,9 @@ public abstract class CachingDirectoryFa
private void close(Directory directory) throws IOException {
synchronized (this) {
+ // don't check if already closed here - we need to able to release
+ // while #close() waits.
+
CacheValue cacheValue = byDirectoryCache.get(directory);
if (cacheValue == null) {
throw new IllegalArgumentException("Unknown directory: " + directory
@@ -146,31 +164,44 @@ public abstract class CachingDirectoryFa
if (cacheValue.refCnt == 0 && cacheValue.doneWithDir) {
log.info("Closing directory:" + cacheValue.path);
- List<CloseListener> listeners = closeListeners.remove(directory);
- if (listeners != null) {
- for (CloseListener listener : listeners) {
- listener.preClose();
- }
- }
+ closeDirectory(cacheValue);
+
+ byDirectoryCache.remove(directory);
+ byPathCache.remove(cacheValue.path);
+ }
+ }
+ }
+
+ private void closeDirectory(CacheValue cacheValue) {
+ List<CloseListener> listeners = closeListeners.remove(cacheValue.directory);
+ if (listeners != null) {
+ for (CloseListener listener : listeners) {
try {
- directory.close();
+ listener.preClose();
} catch (Throwable t) {
- SolrException.log(log, "Error closing directory", t);
+ SolrException.log(log, "Error executing preClose for directory", t);
}
-
- if (listeners != null) {
- for (CloseListener listener : listeners) {
- listener.postClose();
- }
- closeListeners.remove(directory);
+ }
+ }
+ try {
+ log.info("Closing directory:" + cacheValue.path);
+ cacheValue.directory.close();
+ } catch (Throwable t) {
+ SolrException.log(log, "Error closing directory", t);
+ }
+
+ if (listeners != null) {
+ for (CloseListener listener : listeners) {
+ try {
+ listener.postClose();
+ } catch (Throwable t) {
+ SolrException.log(log, "Error executing postClose for directory", t);
}
-
- byDirectoryCache.remove(directory);
- byPathCache.remove(cacheValue.path);
}
}
}
+ @Override
protected abstract Directory create(String path) throws IOException;
@Override
@@ -203,6 +234,10 @@ public abstract class CachingDirectoryFa
throws IOException {
String fullPath = new File(path).getAbsolutePath();
synchronized (this) {
+ if (closed) {
+ throw new RuntimeException("Already closed");
+ }
+
final CacheValue cacheValue = byPathCache.get(fullPath);
Directory directory = null;
if (cacheValue != null) {
@@ -231,6 +266,8 @@ public abstract class CachingDirectoryFa
if (directory == null || forceNew) {
directory = create(fullPath);
+ directory = rateLimit(directory);
+
CacheValue newCacheValue = new CacheValue();
newCacheValue.directory = directory;
newCacheValue.path = fullPath;
@@ -247,6 +284,25 @@ public abstract class CachingDirectoryFa
return directory;
}
}
+
+ private Directory rateLimit(Directory directory) {
+ if (maxWriteMBPerSecDefault != null || maxWriteMBPerSecFlush != null || maxWriteMBPerSecMerge != null || maxWriteMBPerSecRead != null) {
+ directory = new RateLimitedDirectoryWrapper(directory);
+ if (maxWriteMBPerSecDefault != null) {
+ ((RateLimitedDirectoryWrapper)directory).setMaxWriteMBPerSec(maxWriteMBPerSecDefault, Context.DEFAULT);
+ }
+ if (maxWriteMBPerSecFlush != null) {
+ ((RateLimitedDirectoryWrapper)directory).setMaxWriteMBPerSec(maxWriteMBPerSecFlush, Context.FLUSH);
+ }
+ if (maxWriteMBPerSecMerge != null) {
+ ((RateLimitedDirectoryWrapper)directory).setMaxWriteMBPerSec(maxWriteMBPerSecMerge, Context.MERGE);
+ }
+ if (maxWriteMBPerSecRead != null) {
+ ((RateLimitedDirectoryWrapper)directory).setMaxWriteMBPerSec(maxWriteMBPerSecRead, Context.READ);
+ }
+ }
+ return directory;
+ }
/*
* (non-Javadoc)
@@ -255,6 +311,7 @@ public abstract class CachingDirectoryFa
* org.apache.solr.core.DirectoryFactory#incRef(org.apache.lucene.store.Directory
* )
*/
+ @Override
public void incRef(Directory directory) {
synchronized (this) {
CacheValue cacheValue = byDirectoryCache.get(directory);
@@ -266,7 +323,13 @@ public abstract class CachingDirectoryFa
}
}
- public void init(NamedList args) {}
+ @Override
+ public void init(NamedList args) {
+ maxWriteMBPerSecFlush = (Double) args.get("maxWriteMBPerSecFlush");
+ maxWriteMBPerSecMerge = (Double) args.get("maxWriteMBPerSecMerge");
+ maxWriteMBPerSecRead = (Double) args.get("maxWriteMBPerSecRead");
+ maxWriteMBPerSecDefault = (Double) args.get("maxWriteMBPerSecDefault");
+ }
/*
* (non-Javadoc)
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CodecFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CodecFactory.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CodecFactory.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CodecFactory.java Tue Jan 8 03:40:16 2013
@@ -25,6 +25,7 @@ import org.apache.solr.util.plugin.Named
* Factory for plugging in a custom {@link Codec}
*/
public abstract class CodecFactory implements NamedListInitializedPlugin {
+ @Override
public void init(NamedList args) {
}
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CoreContainer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CoreContainer.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CoreContainer.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CoreContainer.java Tue Jan 8 03:40:16 2013
@@ -41,8 +41,7 @@ import java.util.concurrent.ConcurrentHa
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.Future;
-import java.util.concurrent.RejectedExecutionException;
-import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -78,7 +77,6 @@ import org.apache.solr.logging.LogWatche
import org.apache.solr.logging.jul.JulWatcher;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.update.SolrCoreState;
-import org.apache.solr.util.AdjustableSemaphore;
import org.apache.solr.util.DOMUtil;
import org.apache.solr.util.DefaultSolrThreadFactory;
import org.apache.solr.util.FileUtils;
@@ -114,18 +112,19 @@ public class CoreContainer
private static final String CORE_CONFIG = "config";
private static final String CORE_INSTDIR = "instanceDir";
private static final String CORE_DATADIR = "dataDir";
+ private static final String CORE_ULOGDIR = "ulogDir";
private static final String CORE_SCHEMA = "schema";
private static final String CORE_SHARD = "shard";
private static final String CORE_COLLECTION = "collection";
private static final String CORE_ROLES = "roles";
private static final String CORE_PROPERTIES = "properties";
private static final String CORE_LOADONSTARTUP = "loadOnStartup";
- private static final String CORE_SWAPPABLE = "swappable";
+ private static final String CORE_TRANSIENT = "transient";
protected final Map<String, SolrCore> cores = new LinkedHashMap<String, SolrCore>(); // For "permanent" cores
- protected Map<String, SolrCore> swappableCores = new LinkedHashMap<String, SolrCore>(); // For "lazily loaded" cores
+ protected Map<String, SolrCore> transientCores = new LinkedHashMap<String, SolrCore>(); // For "lazily loaded" cores
protected final Map<String, CoreDescriptor> dynamicDescriptors = new LinkedHashMap<String, CoreDescriptor>();
@@ -159,7 +158,9 @@ public class CoreContainer
private String zkHost;
private Map<SolrCore,String> coreToOrigName = new ConcurrentHashMap<SolrCore,String>();
private String leaderVoteWait = LEADER_VOTE_WAIT;
- protected int swappableCacheSize = Integer.MAX_VALUE; // Use as a flag too, if swappableCacheSize set in solr.xml this will be changed
+ private int distribUpdateConnTimeout = 0;
+ private int distribUpdateSoTimeout = 0;
+ protected int transientCacheSize = Integer.MAX_VALUE; // Use as a flag too, if transientCacheSize set in solr.xml this will be changed
private int coreLoadThreads;
{
@@ -242,20 +243,30 @@ public class CoreContainer
} else {
log.info("Zookeeper client=" + zookeeperHost);
}
- zkController = new ZkController(this, zookeeperHost, zkClientTimeout, zkClientConnectTimeout, host, hostPort, hostContext, leaderVoteWait, new CurrentCoreDescriptorProvider() {
-
- @Override
- public List<CoreDescriptor> getCurrentDescriptors() {
- List<CoreDescriptor> descriptors = new ArrayList<CoreDescriptor>(getCoreNames().size());
- for (SolrCore core : getCores()) {
- descriptors.add(core.getCoreDescriptor());
- }
- return descriptors;
- }
- });
-
String confDir = System.getProperty("bootstrap_confdir");
- boolean boostrapConf = Boolean.getBoolean("bootstrap_conf");
+ boolean boostrapConf = Boolean.getBoolean("bootstrap_conf");
+
+ if(!ZkController.checkChrootPath(zookeeperHost, (confDir!=null) || boostrapConf)) {
+ throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
+ "A chroot was specified in ZkHost but the znode doesn't exist. ");
+ }
+
+ zkController = new ZkController(this, zookeeperHost, zkClientTimeout,
+ zkClientConnectTimeout, host, hostPort, hostContext,
+ leaderVoteWait, distribUpdateConnTimeout, distribUpdateSoTimeout,
+ new CurrentCoreDescriptorProvider() {
+
+ @Override
+ public List<CoreDescriptor> getCurrentDescriptors() {
+ List<CoreDescriptor> descriptors = new ArrayList<CoreDescriptor>(
+ getCoreNames().size());
+ for (SolrCore core : getCores()) {
+ descriptors.add(core.getCoreDescriptor());
+ }
+ return descriptors;
+ }
+ });
+
if (zkRun != null && zkServer.getServers().size() > 1 && confDir == null && boostrapConf == false) {
// we are part of an ensemble and we are not uploading the config - pause to give the config time
@@ -360,14 +371,14 @@ public class CoreContainer
return p;
}
- // Trivial helper method for load, note it implements LRU on swappable cores
+ // Trivial helper method for load, note it implements LRU on transient cores
private void allocateLazyCores(Config cfg) {
- swappableCacheSize = cfg.getInt("solr/cores/@swappableCacheSize", Integer.MAX_VALUE);
- if (swappableCacheSize != Integer.MAX_VALUE) {
- swappableCores = new LinkedHashMap<String, SolrCore>(swappableCacheSize, 0.75f, true) {
+ transientCacheSize = cfg.getInt("solr/cores/@transientCacheSize", Integer.MAX_VALUE);
+ if (transientCacheSize != Integer.MAX_VALUE) {
+ transientCores = new LinkedHashMap<String, SolrCore>(transientCacheSize, 0.75f, true) {
@Override
protected boolean removeEldestEntry(Map.Entry<String, SolrCore> eldest) {
- if (size() > swappableCacheSize) {
+ if (size() > transientCacheSize) {
eldest.getValue().close();
return true;
}
@@ -421,6 +432,8 @@ public class CoreContainer
// now.
cfg.substituteProperties();
+ initShardHandler(cfg);
+
allocateLazyCores(cfg);
// Initialize Logging
@@ -446,6 +459,9 @@ public class CoreContainer
if (fname != null) {
if ("JUL".equalsIgnoreCase(fname)) {
logging = new JulWatcher(slf4jImpl);
+// else if( "Log4j".equals(fname) ) {
+// logging = new Log4jWatcher(slf4jImpl);
+// }
} else {
try {
logging = loader.newInstance(fname, LogWatcher.class);
@@ -480,6 +496,9 @@ public class CoreContainer
zkClientTimeout = cfg.getInt("solr/cores/@zkClientTimeout",
DEFAULT_ZK_CLIENT_TIMEOUT);
+ distribUpdateConnTimeout = cfg.getInt("solr/cores/@distribUpdateConnTimeout", 0);
+ distribUpdateSoTimeout = cfg.getInt("solr/cores/@distribUpdateSoTimeout", 0);
+
hostPort = cfg.get("solr/cores/@hostPort", DEFAULT_HOST_PORT);
hostContext = cfg.get("solr/cores/@hostContext", DEFAULT_HOST_CONTEXT);
@@ -529,14 +548,11 @@ public class CoreContainer
XPathConstants.NODESET);
// setup executor to load cores in parallel
- coreLoadExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 5,
- TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
+ coreLoadExecutor = new ThreadPoolExecutor(coreLoadThreads, coreLoadThreads, 1,
+ TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
new DefaultSolrThreadFactory("coreLoadExecutor"));
try {
- // 4 threads at a time max
- final AdjustableSemaphore semaphore = new AdjustableSemaphore(
- coreLoadThreads);
-
+
CompletionService<SolrCore> completionService = new ExecutorCompletionService<SolrCore>(
coreLoadExecutor);
Set<Future<SolrCore>> pending = new HashSet<Future<SolrCore>>();
@@ -595,49 +611,42 @@ public class CoreContainer
.equalsIgnoreCase(opt)) ? true : false);
}
- opt = DOMUtil.getAttr(node, CORE_SWAPPABLE, null);
+ opt = DOMUtil.getAttr(node, CORE_TRANSIENT, null);
if (opt != null) {
- p.setSwappable(("true".equalsIgnoreCase(opt) || "on"
+ p.setTransient(("true".equalsIgnoreCase(opt) || "on"
.equalsIgnoreCase(opt)) ? true : false);
}
- if (!p.isSwappable() && p.isLoadOnStartup()) { // Just like current
- // case.
+ if (p.isLoadOnStartup()) { // The normal case
+
Callable<SolrCore> task = new Callable<SolrCore>() {
+ @Override
public SolrCore call() {
SolrCore c = null;
try {
c = create(p);
- register(name, c, false);
+ if (p.isTransient()) {
+ registerLazyCore(name, c, false);
+ } else {
+ register(name, c, false);
+ }
+
} catch (Throwable t) {
SolrException.log(log, null, t);
if (c != null) {
c.close();
}
}
- semaphore.release();
-
return c;
}
};
-
- try {
- semaphore.acquire();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new SolrException(ErrorCode.SERVER_ERROR,
- "Interrupted while loading SolrCore(s)", e);
- }
-
- try {
- pending.add(completionService.submit(task));
- } catch (RejectedExecutionException e) {
- semaphore.release();
- throw e;
- }
+
+
+ pending.add(completionService.submit(task));
+
} else {
- // Store it away for later use. includes non-swappable but not
+ // Store it away for later use. includes non-transient but not
// loaded at startup cores.
dynamicDescriptors.put(rawName, p);
}
@@ -659,14 +668,12 @@ public class CoreContainer
coreToOrigName.put(c, c.getName());
}
} catch (ExecutionException e) {
- // shouldn't happen since we catch exceptions ourselves
- SolrException.log(SolrCore.log,
- "error sending update request to shard", e);
+ SolrException.log(SolrCore.log, "error loading core", e);
}
} catch (InterruptedException e) {
throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE,
- "interrupted waiting for shard update response", e);
+ "interrupted while loading core", e);
}
}
} finally {
@@ -676,6 +683,27 @@ public class CoreContainer
}
}
+ protected void initShardHandler(Config cfg) {
+ PluginInfo info = null;
+ if (cfg != null) {
+ Node shfn = cfg.getNode("solr/cores/shardHandlerFactory", false);
+
+ if (shfn != null) {
+ info = new PluginInfo(shfn, "shardHandlerFactory", false, true);
+ } else {
+ Map m = new HashMap();
+ m.put("class",HttpShardHandlerFactory.class.getName());
+ info = new PluginInfo("shardHandlerFactory", m, null, Collections.<PluginInfo>emptyList());
+ }
+ }
+
+ HttpShardHandlerFactory fac = new HttpShardHandlerFactory();
+ if (info != null) {
+ fac.init(info);
+ }
+ shardHandlerFactory = fac;
+ }
+
private Document copyDoc(Document document) throws TransformerException {
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer tx = tfactory.newTransformer();
@@ -727,15 +755,15 @@ public class CoreContainer
}
cores.clear();
}
- synchronized (swappableCores) {
- for (SolrCore core : swappableCores.values()) {
+ synchronized (transientCores) {
+ for (SolrCore core : transientCores.values()) {
try {
core.close();
} catch (Throwable t) {
SolrException.log(log, "Error shutting down core", t);
}
}
- swappableCores.clear();
+ transientCores.clear();
}
} finally {
if (shardHandlerFactory != null) {
@@ -794,7 +822,7 @@ public class CoreContainer
}
protected SolrCore registerLazyCore(String name, SolrCore core, boolean returnPrevNotClosed) {
- return registerCore(swappableCores, name, core, returnPrevNotClosed);
+ return registerCore(transientCores, name, core, returnPrevNotClosed);
}
protected SolrCore registerCore(Map<String,SolrCore> whichCores, String name, SolrCore core, boolean returnPrevNotClosed) {
@@ -1029,8 +1057,8 @@ public class CoreContainer
synchronized (cores) {
lst.addAll(this.cores.keySet());
}
- synchronized (swappableCores) {
- lst.addAll(this.swappableCores.keySet());
+ synchronized (transientCores) {
+ lst.addAll(this.transientCores.keySet());
}
return lst;
}
@@ -1047,8 +1075,8 @@ public class CoreContainer
}
}
}
- synchronized (swappableCores) {
- for (Map.Entry<String,SolrCore> entry : swappableCores.entrySet()) {
+ synchronized (transientCores) {
+ for (Map.Entry<String,SolrCore> entry : transientCores.entrySet()) {
if (core == entry.getValue()) {
lst.add(entry.getKey());
}
@@ -1231,30 +1259,30 @@ public class CoreContainer
synchronized (cores) {
core = cores.get(name);
if (core != null) {
- core.open();
+ core.open(); // increment the ref count while still synchronized
return core;
}
}
- if (dynamicDescriptors.size() == 0) return null; // Nobody even tried to define any swappable cores, so we're done.
+ if (dynamicDescriptors.size() == 0) return null; // Nobody even tried to define any transient cores, so we're done.
- // Now look for already loaded swappable cores.
- synchronized (swappableCores) {
- core = swappableCores.get(name);
+ // Now look for already loaded transient cores.
+ synchronized (transientCores) {
+ core = transientCores.get(name);
if (core != null) {
core.open();
return core;
}
}
CoreDescriptor desc = dynamicDescriptors.get(name);
- if (desc == null) { //Nope, no swappable core with this name
+ if (desc == null) { //Nope, no transient core with this name
return null;
}
try {
core = create(desc); // This should throw an error if it fails.
core.open();
- if (desc.isSwappable()) {
- registerLazyCore(name, core, false); // This is a swappable core
+ if (desc.isTransient()) {
+ registerLazyCore(name, core, false); // This is a transient core
} else {
register(name, core, false); // This is a "permanent", although deferred-load core
}
@@ -1363,8 +1391,8 @@ public class CoreContainer
coresAttribs.put("defaultCoreName", defaultCoreName);
}
- if (swappableCacheSize != Integer.MAX_VALUE) {
- coresAttribs.put("swappableCacheSize", Integer.toString(swappableCacheSize));
+ if (transientCacheSize != Integer.MAX_VALUE) {
+ coresAttribs.put("transientCacheSize", Integer.toString(transientCacheSize));
}
addCoresAttrib(coresAttribs, "hostPort", this.hostPort, DEFAULT_HOST_PORT);
@@ -1442,8 +1470,10 @@ public class CoreContainer
addCoreProperty(coreAttribs, coreNode, CORE_SCHEMA, schema, dcore.getDefaultSchemaName());
String dataDir = dcore.dataDir;
+ String ulogDir = dcore.ulogDir;
addCoreProperty(coreAttribs, coreNode, CORE_DATADIR, dataDir, null);
- addCoreProperty(coreAttribs, coreNode, CORE_SWAPPABLE, Boolean.toString(dcore.isSwappable()), null);
+ addCoreProperty(coreAttribs, coreNode, CORE_ULOGDIR, ulogDir, null);
+ addCoreProperty(coreAttribs, coreNode, CORE_TRANSIENT, Boolean.toString(dcore.isTransient()), null);
addCoreProperty(coreAttribs, coreNode, CORE_LOADONSTARTUP, Boolean.toString(dcore.isLoadOnStartup()), null);
CloudDescriptor cd = dcore.getCloudDescriptor();
@@ -1555,18 +1585,7 @@ public class CoreContainer
/** The default ShardHandlerFactory used to communicate with other solr instances */
public ShardHandlerFactory getShardHandlerFactory() {
- synchronized (this) {
- if (shardHandlerFactory == null) {
- Map m = new HashMap();
- m.put("class",HttpShardHandlerFactory.class.getName());
- PluginInfo info = new PluginInfo("shardHandlerFactory", m,null,Collections.<PluginInfo>emptyList());
-
- HttpShardHandlerFactory fac = new HttpShardHandlerFactory();
- fac.init(info);
- shardHandlerFactory = fac;
- }
- return shardHandlerFactory;
- }
+ return shardHandlerFactory;
}
private SolrConfig getSolrConfigFromZk(String zkConfigName, String solrConfigFileName,
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java Tue Jan 8 03:40:16 2013
@@ -31,13 +31,14 @@ public class CoreDescriptor {
protected String name;
protected String instanceDir;
protected String dataDir;
+ protected String ulogDir;
protected String configName;
protected String propertiesName;
protected String schemaName;
private final CoreContainer coreContainer;
private Properties coreProperties;
private boolean loadOnStartup = true;
- private boolean swappable = false;
+ private boolean isTransient = false;
private CloudDescriptor cloudDesc;
@@ -218,11 +219,19 @@ public class CoreDescriptor {
this.loadOnStartup = loadOnStartup;
}
- public boolean isSwappable() {
- return swappable;
+ public boolean isTransient() {
+ return isTransient;
}
- public void setSwappable(boolean swappable) {
- this.swappable = swappable;
+ public void setTransient(boolean aTransient) {
+ this.isTransient = aTransient;
+ }
+
+ public String getUlogDir() {
+ return ulogDir;
+ }
+
+ public void setUlogDir(String ulogDir) {
+ this.ulogDir = ulogDir;
}
}
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java Tue Jan 8 03:40:16 2013
@@ -21,6 +21,7 @@ import java.io.Closeable;
import java.io.IOException;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FlushInfo;
import org.apache.lucene.store.IOContext;
import org.apache.solr.common.SolrException;
import org.apache.solr.core.CachingDirectoryFactory.CloseListener;
@@ -34,7 +35,13 @@ import org.slf4j.LoggerFactory;
*/
public abstract class DirectoryFactory implements NamedListInitializedPlugin,
Closeable {
-
+
+ // Estimate 10M docs, 100GB size, to avoid caching by NRTCachingDirectory
+ // Stayed away from upper bounds of the int/long in case any other code tried to aggregate these numbers.
+ // A large estimate should currently have no other side effects.
+ public static final IOContext IOCONTEXT_NO_CACHE = new IOContext(new FlushInfo(10*1000*1000, 100L*1000*1000*1000));
+
+
private static final Logger log = LoggerFactory.getLogger(DirectoryFactory.class.getName());
/**
@@ -56,6 +63,7 @@ public abstract class DirectoryFactory i
*
* @throws IOException If there is a low-level I/O error.
*/
+ @Override
public abstract void close() throws IOException;
/**
@@ -81,12 +89,22 @@ public abstract class DirectoryFactory i
public abstract void remove(Directory dir) throws IOException;
/**
+ * This remove is special in that it may be called even after
+ * the factory has been closed. Remove only makes sense for
+ * persistent directory factories.
+ *
+ * @param path to remove
+ * @throws IOException If there is a low-level I/O error.
+ */
+ public abstract void remove(String path) throws IOException;
+
+ /**
* Override for more efficient moves.
*
* @throws IOException If there is a low-level I/O error.
*/
- public void move(Directory fromDir, Directory toDir, String fileName) throws IOException {
- fromDir.copy(toDir, fileName, fileName, IOContext.DEFAULT);
+ public void move(Directory fromDir, Directory toDir, String fileName, IOContext ioContext) throws IOException {
+ fromDir.copy(toDir, fileName, fileName, ioContext);
fromDir.deleteFile(fileName);
}
@@ -122,6 +140,12 @@ public abstract class DirectoryFactory i
*/
public abstract void incRef(Directory directory);
+
+ /**
+ * @return true if data is kept after close.
+ */
+ public abstract boolean isPersistent();
+
/**
* Releases the Directory so that it may be closed when it is no longer
* referenced.
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/EphemeralDirectoryFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/EphemeralDirectoryFactory.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/EphemeralDirectoryFactory.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/EphemeralDirectoryFactory.java Tue Jan 8 03:40:16 2013
@@ -44,12 +44,21 @@ public abstract class EphemeralDirectory
}
}
+ public boolean isPersistent() {
+ return false;
+ }
+
@Override
public void remove(Directory dir) throws IOException {
// ram dir does not persist its dir anywhere
}
@Override
+ public void remove(String path) throws IOException {
+ // ram dir does not persist its dir anywhere
+ }
+
+ @Override
public String normalize(String path) throws IOException {
return path;
}
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/IndexDeletionPolicyWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/IndexDeletionPolicyWrapper.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/IndexDeletionPolicyWrapper.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/IndexDeletionPolicyWrapper.java Tue Jan 8 03:40:16 2013
@@ -124,6 +124,7 @@ public class IndexDeletionPolicyWrapper
/**
* Internal use for Lucene... do not explicitly call.
*/
+ @Override
public void onInit(List list) throws IOException {
List<IndexCommitWrapper> wrapperList = wrap(list);
deletionPolicy.onInit(wrapperList);
@@ -134,6 +135,7 @@ public class IndexDeletionPolicyWrapper
/**
* Internal use for Lucene... do not explicitly call.
*/
+ @Override
public void onCommit(List list) throws IOException {
List<IndexCommitWrapper> wrapperList = wrap(list);
deletionPolicy.onCommit(wrapperList);
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/IndexReaderFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/IndexReaderFactory.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/IndexReaderFactory.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/IndexReaderFactory.java Tue Jan 8 03:40:16 2013
@@ -39,6 +39,7 @@ public abstract class IndexReaderFactory
* when declaring an indexReaderFactory in solrconfig.xml
*
*/
+ @Override
public void init(NamedList args) {
Integer v = (Integer)args.get("setTermIndexDivisor");
if (v != null) {
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/JmxMonitoredMap.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/JmxMonitoredMap.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/JmxMonitoredMap.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/JmxMonitoredMap.java Tue Jan 8 03:40:16 2013
@@ -215,6 +215,7 @@ public class JmxMonitoredMap<K, V> exten
this.coreHashCode = coreHashCode;
}
+ @Override
public MBeanInfo getMBeanInfo() {
ArrayList<MBeanAttributeInfo> attrInfoList = new ArrayList<MBeanAttributeInfo>();
@@ -273,6 +274,7 @@ public class JmxMonitoredMap<K, V> exten
return null;
}
+ @Override
public Object getAttribute(String attribute)
throws AttributeNotFoundException, MBeanException, ReflectionException {
Object val;
@@ -307,6 +309,7 @@ public class JmxMonitoredMap<K, V> exten
return null;
}
+ @Override
public AttributeList getAttributes(String[] attributes) {
AttributeList list = new AttributeList();
for (String attribute : attributes) {
@@ -320,16 +323,19 @@ public class JmxMonitoredMap<K, V> exten
return list;
}
+ @Override
public void setAttribute(Attribute attribute)
throws AttributeNotFoundException, InvalidAttributeValueException,
MBeanException, ReflectionException {
throw new UnsupportedOperationException("Operation not Supported");
}
+ @Override
public AttributeList setAttributes(AttributeList attributes) {
throw new UnsupportedOperationException("Operation not Supported");
}
+ @Override
public Object invoke(String actionName, Object[] params, String[] signature)
throws MBeanException, ReflectionException {
throw new UnsupportedOperationException("Operation not Supported");
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.java Tue Jan 8 03:40:16 2013
@@ -46,6 +46,7 @@ public class MMapDirectoryFactory extend
@Override
public void init(NamedList args) {
+ super.init(args);
SolrParams params = SolrParams.toSolrParams( args );
maxChunk = params.getInt("maxChunkSize", MMapDirectory.DEFAULT_MAX_BUFF);
if (maxChunk <= 0){
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/NRTCachingDirectoryFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/NRTCachingDirectoryFactory.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/NRTCachingDirectoryFactory.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/NRTCachingDirectoryFactory.java Tue Jan 8 03:40:16 2013
@@ -35,6 +35,7 @@ public class NRTCachingDirectoryFactory
@Override
public void init(NamedList args) {
+ super.init(args);
SolrParams params = SolrParams.toSolrParams(args);
maxMergeSizeMB = params.getDouble("maxMergeSizeMB", 4);
if (maxMergeSizeMB <= 0){
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/PluginInfo.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/PluginInfo.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/PluginInfo.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/PluginInfo.java Tue Jan 8 03:40:16 2013
@@ -74,7 +74,7 @@ public class PluginInfo {
if (type != null) sb.append("type = " + type + ",");
if (name != null) sb.append("name = " + name + ",");
if (className != null) sb.append("class = " + className + ",");
- if (initArgs.size() > 0) sb.append("args = " + initArgs);
+ if (initArgs != null && initArgs.size() > 0) sb.append("args = " + initArgs);
sb.append("}");
return sb.toString();
}
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/RequestHandlers.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/RequestHandlers.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/RequestHandlers.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/RequestHandlers.java Tue Jan 8 03:40:16 2013
@@ -225,6 +225,7 @@ public final class RequestHandlers {
/**
* In normal use, this function will not be called
*/
+ @Override
public void init(NamedList args) {
// do nothing
}
@@ -232,6 +233,7 @@ public final class RequestHandlers {
/**
* Wait for the first request before initializing the wrapped handler
*/
+ @Override
public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) {
SolrRequestHandler handler = _handler;
if (handler == null) {
@@ -266,10 +268,12 @@ public final class RequestHandlers {
//////////////////////// SolrInfoMBeans methods //////////////////////
+ @Override
public String getName() {
return "Lazy["+_className+"]";
}
+ @Override
public String getDescription()
{
if( _handler == null ) {
@@ -278,6 +282,7 @@ public final class RequestHandlers {
return _handler.getDescription();
}
+ @Override
public String getVersion() {
if( _handler != null ) {
return _handler.getVersion();
@@ -285,6 +290,7 @@ public final class RequestHandlers {
return null;
}
+ @Override
public String getSource() {
String rev = "$URL$";
if( _handler != null ) {
@@ -293,6 +299,7 @@ public final class RequestHandlers {
return rev;
}
+ @Override
public URL[] getDocs() {
if( _handler == null ) {
return null;
@@ -300,11 +307,13 @@ public final class RequestHandlers {
return _handler.getDocs();
}
+ @Override
public Category getCategory()
{
return Category.QUERYHANDLER;
}
+ @Override
public NamedList getStatistics() {
if( _handler != null ) {
return _handler.getStatistics();
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/SolrCore.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/SolrCore.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/SolrCore.java Tue Jan 8 03:40:16 2013
@@ -66,8 +66,10 @@ import org.apache.solr.common.SolrExcept
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.CommonParams.EchoParamStyle;
import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
+import org.apache.solr.handler.SnapPuller;
import org.apache.solr.handler.admin.ShowFileRequestHandler;
import org.apache.solr.handler.component.DebugComponent;
import org.apache.solr.handler.component.FacetComponent;
@@ -236,8 +238,8 @@ public final class SolrCore implements S
Directory dir = null;
try {
dir = getDirectoryFactory().get(getDataDir(), getSolrConfig().indexConfig.lockType);
- if (dir.fileExists("index.properties")){
- final IndexInput input = dir.openInput("index.properties", IOContext.DEFAULT);
+ if (dir.fileExists(SnapPuller.INDEX_PROPERTIES)){
+ final IndexInput input = dir.openInput(SnapPuller.INDEX_PROPERTIES, IOContext.DEFAULT);
final InputStream is = new PropertiesInputStream(input);
try {
@@ -249,7 +251,7 @@ public final class SolrCore implements S
}
} catch (Exception e) {
- log.error("Unable to load index.properties", e);
+ log.error("Unable to load " + SnapPuller.INDEX_PROPERTIES, e);
} finally {
IOUtils.closeQuietly(is);
}
@@ -257,11 +259,12 @@ public final class SolrCore implements S
} catch (IOException e) {
SolrException.log(log, "", e);
} finally {
-
- try {
- getDirectoryFactory().release(dir);
- } catch (IOException e) {
- SolrException.log(log, "", e);
+ if (dir != null) {
+ try {
+ getDirectoryFactory().release(dir);
+ } catch (IOException e) {
+ SolrException.log(log, "", e);
+ }
}
}
if (!result.equals(lastNewIndexDir)) {
@@ -281,6 +284,7 @@ public final class SolrCore implements S
return indexReaderFactory;
}
+ @Override
public String getName() {
return name;
}
@@ -562,6 +566,9 @@ public final class SolrCore implements S
} else if (o instanceof NamedListInitializedPlugin) {
((NamedListInitializedPlugin) o).init(info.initArgs);
}
+ if(o instanceof SearchComponent) {
+ ((SearchComponent) o).setName(info.name);
+ }
return o;
}
@@ -729,6 +736,7 @@ public final class SolrCore implements S
// until after inform() has been called for all components.
// searchExecutor must be single-threaded for this to work
searcherExecutor.submit(new Callable() {
+ @Override
public Object call() throws Exception {
latch.await();
return null;
@@ -954,7 +962,7 @@ public final class SolrCore implements S
try {
infoRegistry.clear();
- } catch (Exception e) {
+ } catch (Throwable e) {
SolrException.log(log, e);
}
@@ -977,22 +985,11 @@ public final class SolrCore implements S
}
try {
- searcherExecutor.shutdown();
- if (!searcherExecutor.awaitTermination(60, TimeUnit.SECONDS)) {
- log.error("Timeout waiting for searchExecutor to terminate");
- }
- } catch (InterruptedException e) {
- searcherExecutor.shutdownNow();
- try {
- if (!searcherExecutor.awaitTermination(30, TimeUnit.SECONDS)) {
- log.error("Timeout waiting for searchExecutor to terminate");
- }
- } catch (InterruptedException e2) {
- SolrException.log(log, e2);
- }
- } catch (Exception e) {
+ ExecutorUtil.shutdownAndAwaitTermination(searcherExecutor);
+ } catch (Throwable e) {
SolrException.log(log, e);
}
+
try {
// Since we waited for the searcherExecutor to shut down,
// there should be no more searchers warming in the background
@@ -1166,7 +1163,10 @@ public final class SolrCore implements S
if(!registry.containsKey(name)){
T searchComp = resourceLoader.newInstance(c.getName(), c);
if (searchComp instanceof NamedListInitializedPlugin){
- ((NamedListInitializedPlugin)searchComp).init( new NamedList() );
+ ((NamedListInitializedPlugin)searchComp).init( new NamedList<String>() );
+ }
+ if(searchComp instanceof SearchComponent) {
+ ((SearchComponent)searchComp).setName(name);
}
registry.put(name, searchComp);
if (searchComp instanceof SolrInfoMBean){
@@ -1570,6 +1570,7 @@ public final class SolrCore implements S
if (currSearcher != null) {
future = searcherExecutor.submit(
new Callable() {
+ @Override
public Object call() throws Exception {
try {
newSearcher.warm(currSearcher);
@@ -1585,6 +1586,7 @@ public final class SolrCore implements S
if (currSearcher==null && firstSearcherListeners.size() > 0) {
future = searcherExecutor.submit(
new Callable() {
+ @Override
public Object call() throws Exception {
try {
for (SolrEventListener listener : firstSearcherListeners) {
@@ -1602,6 +1604,7 @@ public final class SolrCore implements S
if (currSearcher!=null && newSearcherListeners.size() > 0) {
future = searcherExecutor.submit(
new Callable() {
+ @Override
public Object call() throws Exception {
try {
for (SolrEventListener listener : newSearcherListeners) {
@@ -1622,6 +1625,7 @@ public final class SolrCore implements S
if (!alreadyRegistered) {
future = searcherExecutor.submit(
new Callable() {
+ @Override
public Object call() throws Exception {
try {
// registerSearcher will decrement onDeckSearchers and
@@ -2165,31 +2169,38 @@ public final class SolrCore implements S
// SolrInfoMBean stuff: Statistics and Module Info
/////////////////////////////////////////////////////////////////////
+ @Override
public String getVersion() {
return SolrCore.version;
}
+ @Override
public String getDescription() {
return "SolrCore";
}
+ @Override
public Category getCategory() {
return Category.CORE;
}
+ @Override
public String getSource() {
return "$URL$";
}
+ @Override
public URL[] getDocs() {
return null;
}
+ @Override
public NamedList getStatistics() {
NamedList<Object> lst = new SimpleOrderedMap<Object>();
lst.add("coreName", name==null ? "(null)" : name);
lst.add("startTime", new Date(startTime));
lst.add("refCount", getOpenCount());
+ lst.add("indexDir", getIndexDir());
CoreDescriptor cd = getCoreDescriptor();
if (cd != null) {
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java Tue Jan 8 03:40:16 2013
@@ -48,6 +48,7 @@ public class SolrDeletionPolicy implemen
private int maxCommitsToKeep = 1;
private int maxOptimizedCommitsToKeep = 0;
+ @Override
public void init(NamedList args) {
String keepOptimizedOnlyString = (String) args.get("keepOptimizedOnly");
String maxCommitsToKeepString = (String) args.get("maxCommitsToKeep");
@@ -109,6 +110,7 @@ public class SolrDeletionPolicy implemen
/**
* Internal use for Lucene... do not explicitly call.
*/
+ @Override
public void onInit(List commits) throws IOException {
log.info("SolrDeletionPolicy.onInit: commits:" + str(commits));
updateCommits((List<IndexCommit>) commits);
@@ -117,6 +119,7 @@ public class SolrDeletionPolicy implemen
/**
* Internal use for Lucene... do not explicitly call.
*/
+ @Override
public void onCommit(List commits) throws IOException {
log.info("SolrDeletionPolicy.onCommit: commits:" + str(commits));
updateCommits((List<IndexCommit>) commits);
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java Tue Jan 8 03:40:16 2013
@@ -160,6 +160,7 @@ public class SolrResourceLoader implemen
if (file.canRead()) {
this.classLoader = replaceClassLoader(classLoader, file.getParentFile(),
new FileFilter() {
+ @Override
public boolean accept(File pathname) {
return pathname.equals(file);
}
@@ -290,6 +291,7 @@ public class SolrResourceLoader implemen
* Override this method to customize loading resources.
*@return the stream for the named resource
*/
+ @Override
public InputStream openResource(String resource) throws IOException {
InputStream is=null;
try {
@@ -451,6 +453,7 @@ public class SolrResourceLoader implemen
static final String empty[] = new String[0];
+ @Override
public <T> T newInstance(String name, Class<T> expectedType) {
return newInstance(name, expectedType, empty);
}
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java Tue Jan 8 03:40:16 2013
@@ -22,6 +22,7 @@ import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.IOContext;
/**
* Directory provider which mimics original Solr
@@ -43,23 +44,36 @@ public class StandardDirectoryFactory ex
return new File(path).getCanonicalPath();
}
+ public boolean isPersistent() {
+ return true;
+ }
+
@Override
public void remove(Directory dir) throws IOException {
CacheValue val = byDirectoryCache.get(dir);
if (val == null) {
- throw new NullPointerException("Unknown directory " + dir);
+ throw new IllegalArgumentException("Unknown directory " + dir);
}
File dirFile = new File(val.path);
FileUtils.deleteDirectory(dirFile);
}
+
+ @Override
+ public void remove(String path) throws IOException {
+ String fullPath = new File(path).getAbsolutePath();
+ File dirFile = new File(fullPath);
+ FileUtils.deleteDirectory(dirFile);
+ }
+
/**
* Override for more efficient moves.
*
* @throws IOException
* If there is a low-level I/O error.
*/
- public void move(Directory fromDir, Directory toDir, String fileName)
+ @Override
+ public void move(Directory fromDir, Directory toDir, String fileName, IOContext ioContext)
throws IOException {
if (fromDir instanceof FSDirectory && toDir instanceof FSDirectory) {
File dir1 = ((FSDirectory) fromDir).getDirectory();
@@ -72,6 +86,7 @@ public class StandardDirectoryFactory ex
}
}
- super.move(fromDir, toDir, fileName);
+ super.move(fromDir, toDir, fileName, ioContext);
}
+
}
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/AnalysisRequestHandlerBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/AnalysisRequestHandlerBase.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/AnalysisRequestHandlerBase.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/AnalysisRequestHandlerBase.java Tue Jan 8 03:40:16 2013
@@ -212,6 +212,7 @@ public abstract class AnalysisRequestHan
// sort the tokens by absoulte position
ArrayUtil.mergeSort(tokens, new Comparator<AttributeSource>() {
+ @Override
public int compare(AttributeSource a, AttributeSource b) {
return arrayCompare(
a.getAttribute(TokenTrackingAttribute.class).getPositions(),
@@ -255,6 +256,7 @@ public abstract class AnalysisRequestHan
}
token.reflectWith(new AttributeReflector() {
+ @Override
public void reflect(Class<? extends Attribute> attClass, String key, Object value) {
// leave out position and bytes term
if (TermToBytesRefAttribute.class.isAssignableFrom(attClass))
@@ -365,17 +367,20 @@ public abstract class AnalysisRequestHan
private int position = 0;
private transient int[] cachedPositions = null;
+ @Override
public void freezeStage() {
this.basePositions = getPositions();
this.position = 0;
this.cachedPositions = null;
}
+ @Override
public void setActPosition(int pos) {
this.position = pos;
this.cachedPositions = null;
}
+ @Override
public int[] getPositions() {
if (cachedPositions == null) {
cachedPositions = ArrayUtils.add(basePositions, position);
@@ -383,6 +388,7 @@ public abstract class AnalysisRequestHan
return cachedPositions;
}
+ @Override
public void reset(int[] basePositions, int position) {
this.basePositions = basePositions;
this.position = position;
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java Tue Jan 8 03:40:16 2013
@@ -76,7 +76,7 @@ public class MoreLikeThisHandler extends
SolrParams params = req.getParams();
// Set field flags
- ReturnFields returnFields = new ReturnFields( req );
+ ReturnFields returnFields = new SolrReturnFields( req );
rsp.setReturnFields( returnFields );
int flags = 0;
if (returnFields.wantsScore()) {
@@ -257,6 +257,7 @@ public class MoreLikeThisHandler extends
public float boost;
public static Comparator<InterestingTerm> BOOST_ORDER = new Comparator<InterestingTerm>() {
+ @Override
public int compare(InterestingTerm t1, InterestingTerm t2) {
float d = t1.boost - t2.boost;
if( d == 0 ) {
@@ -400,6 +401,33 @@ public class MoreLikeThisHandler extends
return mlt;
}
+ public NamedList<BooleanQuery> getMoreLikeTheseQuery(DocList docs)
+ throws IOException {
+ IndexSchema schema = searcher.getSchema();
+ NamedList<BooleanQuery> result = new NamedList<BooleanQuery>();
+ DocIterator iterator = docs.iterator();
+ while (iterator.hasNext()) {
+ int id = iterator.nextDoc();
+ String uniqueId = schema.printableUniqueKey(reader.document(id));
+
+ BooleanQuery mltquery = (BooleanQuery) mlt.like(id);
+ if (mltquery.clauses().size() == 0) {
+ return result;
+ }
+ mltquery = (BooleanQuery) getBoostedQuery(mltquery);
+
+ // exclude current document from results
+ BooleanQuery mltQuery = new BooleanQuery();
+ mltQuery.add(mltquery, BooleanClause.Occur.MUST);
+
+ mltQuery.add(
+ new TermQuery(new Term(uniqueKeyField.getName(), uniqueId)), BooleanClause.Occur.MUST_NOT);
+ result.add(uniqueId, mltQuery);
+ }
+
+ return result;
+ }
+
private void fillInterestingTermsFromMLTQuery( Query query, List<InterestingTerm> terms )
{
List clauses = ((BooleanQuery)query).clauses();
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java Tue Jan 8 03:40:16 2013
@@ -134,12 +134,14 @@ public class PingRequestHandler extends
private String healthFileName = null;
private File healthcheck = null;
+ @Override
public void init(NamedList args) {
super.init(args);
Object tmp = args.get(HEALTHCHECK_FILE_PARAM);
healthFileName = (null == tmp ? null : tmp.toString());
}
+ @Override
public void inform( SolrCore core ) {
if (null != healthFileName) {
healthcheck = new File(healthFileName);
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java Tue Jan 8 03:40:16 2013
@@ -777,6 +777,7 @@ public class ReplicationHandler extends
// }
// }
+ @Override
@SuppressWarnings("unchecked")
public void inform(SolrCore core) {
this.core = core;
@@ -927,19 +928,23 @@ public class ReplicationHandler extends
*/
private void registerFileStreamResponseWriter() {
core.registerResponseWriter(FILE_STREAM, new BinaryQueryResponseWriter() {
+ @Override
public void write(OutputStream out, SolrQueryRequest request, SolrQueryResponse resp) throws IOException {
DirectoryFileStream stream = (DirectoryFileStream) resp.getValues().get(FILE_STREAM);
stream.write(out);
}
+ @Override
public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response) {
throw new RuntimeException("This is a binary writer , Cannot write to a characterstream");
}
+ @Override
public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {
return "application/octet-stream";
}
+ @Override
public void init(NamedList args) { /*no op*/ }
});
@@ -955,11 +960,13 @@ public class ReplicationHandler extends
*/
private SolrEventListener getEventListener(final boolean snapshoot, final boolean getCommit) {
return new SolrEventListener() {
+ @Override
public void init(NamedList args) {/*no op*/ }
/**
* This refreshes the latest replicateable index commit and optionally can create Snapshots as well
*/
+ @Override
public void postCommit() {
IndexCommit currentCommitPoint = core.getDeletionPolicy().getLatestCommit();
@@ -992,6 +999,7 @@ public class ReplicationHandler extends
}
}
+ @Override
public void newSearcher(SolrIndexSearcher newSearcher, SolrIndexSearcher currentSearcher) { /*no op*/}
@Override
@@ -1110,6 +1118,7 @@ public class ReplicationHandler extends
super(solrParams);
}
+ @Override
public void write(OutputStream out) throws IOException {
String fileName = params.get(FILE);
String cfileName = params.get(CONF_FILE_SHORT);
Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java?rev=1430130&r1=1430129&r2=1430130&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java Tue Jan 8 03:40:16 2013
@@ -17,11 +17,6 @@
package org.apache.solr.handler;
-import com.yammer.metrics.Metrics;
-import com.yammer.metrics.core.Counter;
-import com.yammer.metrics.core.Timer;
-import com.yammer.metrics.core.TimerContext;
-import com.yammer.metrics.stats.Snapshot;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
@@ -33,6 +28,9 @@ import org.apache.solr.request.SolrReque
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.search.SyntaxError;
import org.apache.solr.util.SolrPluginUtils;
+import org.apache.solr.util.stats.Snapshot;
+import org.apache.solr.util.stats.Timer;
+import org.apache.solr.util.stats.TimerContext;
import java.net.URL;
import java.util.concurrent.atomic.AtomicLong;
@@ -49,20 +47,11 @@ public abstract class RequestHandlerBase
protected boolean httpCaching = true;
// Statistics
- private static final AtomicLong handlerNumber = new AtomicLong();
- private final Counter numRequests;
- private final Counter numErrors;
- private final Counter numTimeouts;
- private final Timer requestTimes;
- long handlerStart = System.currentTimeMillis();
-
- public RequestHandlerBase() {
- String scope = new String("metrics-scope-" + handlerNumber.getAndIncrement());
- numRequests = Metrics.newCounter(RequestHandlerBase.class, "numRequests", scope);
- numErrors = Metrics.newCounter(RequestHandlerBase.class, "numErrors", scope);
- numTimeouts = Metrics.newCounter(RequestHandlerBase.class, "numTimeouts", scope);
- requestTimes = Metrics.newTimer(RequestHandlerBase.class, "requestTimes", scope);
- }
+ private final AtomicLong numRequests = new AtomicLong();
+ private final AtomicLong numErrors = new AtomicLong();
+ private final AtomicLong numTimeouts = new AtomicLong();
+ private final Timer requestTimes = new Timer();
+ private final long handlerStart = System.currentTimeMillis();
/**
* Initializes the {@link org.apache.solr.request.SolrRequestHandler} by creating three {@link org.apache.solr.common.params.SolrParams} named.
@@ -103,6 +92,7 @@ public abstract class RequestHandlerBase
*
* See also the example solrconfig.xml located in the Solr codebase (example/solr/conf).
*/
+ @Override
public void init(NamedList args) {
initArgs = args;
@@ -135,8 +125,9 @@ public abstract class RequestHandlerBase
public abstract void handleRequestBody( SolrQueryRequest req, SolrQueryResponse rsp ) throws Exception;
+ @Override
public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) {
- numRequests.inc();
+ numRequests.incrementAndGet();
TimerContext timer = requestTimes.time();
try {
SolrPluginUtils.setDefaults(req,defaults,appends,invariants);
@@ -148,7 +139,7 @@ public abstract class RequestHandlerBase
Object partialResults = header.get("partialResults");
boolean timedOut = partialResults == null ? false : (Boolean)partialResults;
if( timedOut ) {
- numTimeouts.inc();
+ numTimeouts.incrementAndGet();
rsp.setHttpCaching(false);
}
}
@@ -169,7 +160,7 @@ public abstract class RequestHandlerBase
}
rsp.setException(e);
- numErrors.inc();
+ numErrors.incrementAndGet();
}
finally {
timer.stop();
@@ -178,37 +169,44 @@ public abstract class RequestHandlerBase
//////////////////////// SolrInfoMBeans methods //////////////////////
+ @Override
public String getName() {
return this.getClass().getName();
}
+ @Override
public abstract String getDescription();
+ @Override
public abstract String getSource();
+ @Override
public String getVersion() {
return getClass().getPackage().getSpecificationVersion();
}
+ @Override
public Category getCategory() {
return Category.QUERYHANDLER;
}
+ @Override
public URL[] getDocs() {
return null; // this can be overridden, but not required
}
+ @Override
public NamedList<Object> getStatistics() {
NamedList<Object> lst = new SimpleOrderedMap<Object>();
- lst.add("handlerStart",handlerStart);
- lst.add("requests", numRequests.count());
- lst.add("errors", numErrors.count());
- lst.add("timeouts", numTimeouts.count());
- lst.add("totalTime",requestTimes.sum());
- lst.add("avgRequestsPerSecond", requestTimes.meanRate());
- lst.add("5minRateReqsPerSecond", requestTimes.fiveMinuteRate());
- lst.add("15minRateReqsPerSecond", requestTimes.fifteenMinuteRate());
- lst.add("avgTimePerRequest", requestTimes.mean());
Snapshot snapshot = requestTimes.getSnapshot();
+ lst.add("handlerStart",handlerStart);
+ lst.add("requests", numRequests.longValue());
+ lst.add("errors", numErrors.longValue());
+ lst.add("timeouts", numTimeouts.longValue());
+ lst.add("totalTime", requestTimes.getSum());
+ lst.add("avgRequestsPerSecond", requestTimes.getMeanRate());
+ lst.add("5minRateReqsPerSecond", requestTimes.getFiveMinuteRate());
+ lst.add("15minRateReqsPerSecond", requestTimes.getFifteenMinuteRate());
+ lst.add("avgTimePerRequest", requestTimes.getMean());
lst.add("medianRequestTime", snapshot.getMedian());
lst.add("75thPcRequestTime", snapshot.get75thPercentile());
lst.add("95thPcRequestTime", snapshot.get95thPercentile());