mirror of https://github.com/apache/lucene.git
SOLR-6801: Fix formatting.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1647018 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ce7da69d2c
commit
3d70e67002
|
@ -17,6 +17,8 @@ package org.apache.solr.core;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import static org.apache.solr.common.SolrException.ErrorCode.SERVICE_UNAVAILABLE;
|
||||
import static org.apache.solr.common.cloud.ZkStateReader.BASE_URL_PROP;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -36,68 +38,63 @@ import org.apache.solr.common.cloud.ClusterState;
|
|||
import org.apache.solr.common.cloud.DocCollection;
|
||||
import org.apache.solr.common.cloud.Replica;
|
||||
import org.apache.solr.common.cloud.Slice;
|
||||
import org.apache.solr.handler.BlobHandler;
|
||||
import org.apache.solr.handler.admin.CollectionsHandler;
|
||||
import org.apache.solr.util.SimplePostTool;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.apache.solr.common.SolrException.ErrorCode.SERVICE_UNAVAILABLE;
|
||||
import static org.apache.solr.common.cloud.ZkStateReader.BASE_URL_PROP;
|
||||
|
||||
/**The purpose of this class is to store the Jars loaded in memory and to keep
|
||||
* only one copy of the Jar in a single node.
|
||||
/**
|
||||
* The purpose of this class is to store the Jars loaded in memory and to keep only one copy of the Jar in a single node.
|
||||
*/
|
||||
public class JarRepository {
|
||||
public static Logger log = LoggerFactory.getLogger(JarRepository.class);
|
||||
|
||||
private final CoreContainer coreContainer;
|
||||
|
||||
private Map<String, JarContent> jars = new ConcurrentHashMap<>();
|
||||
private Map<String,JarContent> jars = new ConcurrentHashMap<>();
|
||||
|
||||
public JarRepository(CoreContainer coreContainer) {
|
||||
this.coreContainer = coreContainer;
|
||||
}
|
||||
|
||||
/**Returns the contents of a jar and increments a reference count. Please return the same
|
||||
* object to decerease the refcount
|
||||
* @param key it is a combination of blobname and version like blobName/version
|
||||
/**
|
||||
* Returns the contents of a jar and increments a reference count. Please return the same object to decerease the refcount
|
||||
*
|
||||
* @param key
|
||||
* it is a combination of blobname and version like blobName/version
|
||||
* @return The reference of a jar
|
||||
*/
|
||||
public JarContentRef getJarIncRef(String key) throws IOException {
|
||||
JarContent jar = jars.get(key);
|
||||
if(jar ==null){
|
||||
if(this.coreContainer.isZooKeeperAware()){
|
||||
if (jar == null) {
|
||||
if (this.coreContainer.isZooKeeperAware()) {
|
||||
ClusterState cs = this.coreContainer.getZkController().getZkStateReader().getClusterState();
|
||||
DocCollection coll = cs.getCollectionOrNull(CollectionsHandler.SYSTEM_COLL);
|
||||
if(coll == null) throw new SolrException(SERVICE_UNAVAILABLE,
|
||||
".system collection not available");
|
||||
if (coll == null) throw new SolrException(SERVICE_UNAVAILABLE, ".system collection not available");
|
||||
Slice slice = coll.getActiveSlices().iterator().next();
|
||||
if(slice == null) throw new SolrException(SERVICE_UNAVAILABLE,
|
||||
".no active slices for .system collection");
|
||||
if (slice == null) throw new SolrException(SERVICE_UNAVAILABLE, ".no active slices for .system collection");
|
||||
Replica replica = slice.getReplicas().iterator().next();
|
||||
if(replica == null) throw new SolrException(SERVICE_UNAVAILABLE,
|
||||
".no active replica available for .system collection");
|
||||
String url = replica.getStr(BASE_URL_PROP) + "/.system/blob/"+ key+"?wt=filestream";
|
||||
if (replica == null) throw new SolrException(SERVICE_UNAVAILABLE, ".no active replica available for .system collection");
|
||||
String url = replica.getStr(BASE_URL_PROP) + "/.system/blob/" + key + "?wt=filestream";
|
||||
|
||||
HttpClient httpClient = coreContainer.getUpdateShardHandler().getHttpClient();
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
ByteBuffer b;
|
||||
try {
|
||||
HttpResponse entity = httpClient.execute(httpGet);
|
||||
HttpResponse entity = httpClient.execute(httpGet);
|
||||
int statusCode = entity.getStatusLine().getStatusCode();
|
||||
if(statusCode != 200){
|
||||
throw new SolrException(SolrException.ErrorCode.NOT_FOUND,"no such blob or version available: "+ key);
|
||||
if (statusCode != 200) {
|
||||
throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "no such blob or version available: " + key);
|
||||
}
|
||||
b = SimplePostTool.inputStreamToByteArray(entity.getEntity().getContent());
|
||||
} finally {
|
||||
httpGet.releaseConnection();
|
||||
}
|
||||
jars.put(key,jar = new JarContent(key,b));
|
||||
jars.put(key, jar = new JarContent(key, b));
|
||||
} else {
|
||||
|
||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"Jar loading is not supported in non-cloud mode");
|
||||
//todo
|
||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Jar loading is not supported in non-cloud mode");
|
||||
// todo
|
||||
|
||||
}
|
||||
|
||||
|
@ -111,12 +108,14 @@ public class JarRepository {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**This is to decrement a ref count
|
||||
* @param ref The reference that is already there. Doing multiple calls with same ref will not matter
|
||||
/**
|
||||
* This is to decrement a ref count
|
||||
*
|
||||
* @param ref
|
||||
* The reference that is already there. Doing multiple calls with same ref will not matter
|
||||
*/
|
||||
public void decrementJarRefCount(JarContentRef ref){
|
||||
if(ref == null) return;
|
||||
public void decrementJarRefCount(JarContentRef ref) {
|
||||
if (ref == null) return;
|
||||
synchronized (ref.jar.references) {
|
||||
if (!ref.jar.references.remove(ref)) {
|
||||
log.error("Multiple releases for the same reference");
|
||||
|
@ -128,10 +127,9 @@ public class JarRepository {
|
|||
|
||||
}
|
||||
|
||||
|
||||
public static class JarContent {
|
||||
private final String key;
|
||||
//TODO move this off-heap
|
||||
// TODO move this off-heap
|
||||
private final ByteBuffer buffer;
|
||||
// ref counting mechanism
|
||||
private final Set<JarContentRef> references = new HashSet<>();
|
||||
|
@ -142,17 +140,17 @@ public class JarRepository {
|
|||
}
|
||||
|
||||
public ByteBuffer getFileContent(String entryName) throws IOException {
|
||||
ByteArrayInputStream zipContents=new ByteArrayInputStream(buffer.array(),buffer.arrayOffset(),buffer.limit());
|
||||
ZipInputStream zis=new ZipInputStream(zipContents);
|
||||
ByteArrayInputStream zipContents = new ByteArrayInputStream(buffer.array(), buffer.arrayOffset(), buffer.limit());
|
||||
ZipInputStream zis = new ZipInputStream(zipContents);
|
||||
try {
|
||||
ZipEntry entry;
|
||||
while ((entry=zis.getNextEntry()) != null) {
|
||||
while ((entry = zis.getNextEntry()) != null) {
|
||||
if (entryName == null || entryName.equals(entry.getName())) {
|
||||
SimplePostTool.BAOS out=new SimplePostTool.BAOS();
|
||||
byte[] buffer=new byte[2048];
|
||||
SimplePostTool.BAOS out = new SimplePostTool.BAOS();
|
||||
byte[] buffer = new byte[2048];
|
||||
int size;
|
||||
while ((size=zis.read(buffer,0,buffer.length)) != -1) {
|
||||
out.write(buffer,0,size);
|
||||
while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
|
||||
out.write(buffer, 0, size);
|
||||
}
|
||||
out.close();
|
||||
return out.getByteBuffer();
|
||||
|
@ -166,8 +164,9 @@ public class JarRepository {
|
|||
|
||||
}
|
||||
|
||||
public static class JarContentRef {
|
||||
public static class JarContentRef {
|
||||
public final JarContent jar;
|
||||
|
||||
private JarContentRef(JarContent jar) {
|
||||
this.jar = jar;
|
||||
}
|
||||
|
|
|
@ -119,8 +119,8 @@ public final class RequestHandlers {
|
|||
*/
|
||||
public SolrRequestHandler register( String handlerName, SolrRequestHandler handler ) {
|
||||
String norm = normalize( handlerName );
|
||||
if( handler == null ) {
|
||||
return handlers.remove( norm );
|
||||
if (handler == null) {
|
||||
return handlers.remove(norm);
|
||||
}
|
||||
SolrRequestHandler old = handlers.put(norm, handler);
|
||||
if (0 != norm.length() && handler instanceof SolrInfoMBean) {
|
||||
|
@ -165,7 +165,7 @@ public final class RequestHandlers {
|
|||
//deduping implicit and explicit requesthandlers
|
||||
for (PluginInfo info : implicits) infoMap.put(info.name,info);
|
||||
for (PluginInfo info : config.getPluginInfos(SolrRequestHandler.class.getName()))
|
||||
if(infoMap.containsKey(info.name)) infoMap.remove(info.name);
|
||||
if (infoMap.containsKey(info.name)) infoMap.remove(info.name);
|
||||
for (Map.Entry e : core.getSolrConfig().getOverlay().getReqHandlers().entrySet())
|
||||
infoMap.put((String)e.getKey(), new PluginInfo(SolrRequestHandler.TYPE, (Map)e.getValue()));
|
||||
|
||||
|
@ -174,33 +174,32 @@ public final class RequestHandlers {
|
|||
for (PluginInfo info : infos) {
|
||||
try {
|
||||
SolrRequestHandler requestHandler;
|
||||
String startup = info.attributes.get("startup") ;
|
||||
String startup = info.attributes.get("startup");
|
||||
String lib = info.attributes.get("lib");
|
||||
if(lib != null){
|
||||
if (lib != null) {
|
||||
requestHandler = new DynamicLazyRequestHandlerWrapper(core);
|
||||
} else if( startup != null ) {
|
||||
if( "lazy".equals(startup) ) {
|
||||
} else if (startup != null) {
|
||||
if ("lazy".equals(startup)) {
|
||||
log.info("adding lazy requestHandler: " + info.className);
|
||||
requestHandler = new LazyRequestHandlerWrapper( core);
|
||||
requestHandler = new LazyRequestHandlerWrapper(core);
|
||||
} else {
|
||||
throw new Exception( "Unknown startup value: '"+startup+"' for: "+info.className );
|
||||
throw new Exception("Unknown startup value: '" + startup + "' for: " + info.className);
|
||||
}
|
||||
} else {
|
||||
requestHandler = core.createRequestHandler(info.className);
|
||||
}
|
||||
if (requestHandler instanceof RequestHandlerBase) ((RequestHandlerBase) requestHandler).setPluginInfo(info);
|
||||
|
||||
handlers.put(info,requestHandler);
|
||||
handlers.put(info, requestHandler);
|
||||
SolrRequestHandler old = register(info.name, requestHandler);
|
||||
if(old != null) {
|
||||
if (old != null) {
|
||||
log.warn("Multiple requestHandler registered to the same name: " + info.name + " ignoring: " + old.getClass().getName());
|
||||
}
|
||||
if(info.isDefault()){
|
||||
old = register("",requestHandler);
|
||||
if(old != null)
|
||||
log.warn("Multiple default requestHandler registered" + " ignoring: " + old.getClass().getName());
|
||||
if (info.isDefault()) {
|
||||
old = register("", requestHandler);
|
||||
if (old != null) log.warn("Multiple default requestHandler registered" + " ignoring: " + old.getClass().getName());
|
||||
}
|
||||
log.info("created "+info.name+": " + info.className);
|
||||
log.info("created " + info.name + ": " + info.className);
|
||||
} catch (Exception ex) {
|
||||
throw new SolrException
|
||||
(ErrorCode.SERVER_ERROR, "RequestHandler init failure", ex);
|
||||
|
@ -387,8 +386,8 @@ public final class RequestHandlers {
|
|||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
if(_handler == null) return;
|
||||
if (_handler instanceof AutoCloseable && !(_handler instanceof DynamicLazyRequestHandlerWrapper) ) {
|
||||
if (_handler == null) return;
|
||||
if (_handler instanceof AutoCloseable && !(_handler instanceof DynamicLazyRequestHandlerWrapper)) {
|
||||
((AutoCloseable) _handler).close();
|
||||
}
|
||||
}
|
||||
|
@ -493,7 +492,7 @@ public final class RequestHandlers {
|
|||
@Override
|
||||
public void close() throws Exception {
|
||||
super.close();
|
||||
if(_closed) return;
|
||||
if (_closed) return;
|
||||
classLoader.releaseJar();
|
||||
_closed = true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue