From: <sp...@us...> - 2011-03-17 05:47:06
|
Revision: 7470 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=7470&view=rev Author: sppigot Date: 2011-03-17 05:47:00 +0000 (Thu, 17 Mar 2011) Log Message: ----------- Fixes for too many open files caused by some guiservices not closing searchers they have opened and by a check which did not allow the IndexReader ref count to return to 0 Modified Paths: -------------- sandbox/BlueNetMEST/ANZMEST/web/src/main/java/org/fao/geonet/guiservices/metadata/GetRandom.java sandbox/BlueNetMEST/ANZMEST/web/src/main/java/org/fao/geonet/guiservices/metadata/GetRelated.java sandbox/BlueNetMEST/ANZMEST/web/src/main/java/org/fao/geonet/kernel/search/LuceneIndexReaderFactory.java Modified: sandbox/BlueNetMEST/ANZMEST/web/src/main/java/org/fao/geonet/guiservices/metadata/GetRandom.java =================================================================== --- sandbox/BlueNetMEST/ANZMEST/web/src/main/java/org/fao/geonet/guiservices/metadata/GetRandom.java 2011-03-16 14:37:48 UTC (rev 7469) +++ sandbox/BlueNetMEST/ANZMEST/web/src/main/java/org/fao/geonet/guiservices/metadata/GetRandom.java 2011-03-17 05:47:00 UTC (rev 7470) @@ -98,43 +98,46 @@ SearchManager searchMan = gc.getSearchmanager(); MetaSearcher searcher = searchMan.newSearcher(SearchManager.LUCENE, Geonet.File.SEARCH_LUCENE); - // FIXME: featured should be at metadata level, not at group level - Element searchRequest = new Element("request"); - searchRequest.addContent(new Element(Geonet.SearchResult.BUILD_SUMMARY).setText("false")); - searchRequest.addContent(new Element("featured").setText("true")); - searchRequest.addContent(new Element("relation").setText(_relation)); - searchRequest.addContent(new Element("northBL").setText(_northBL)); - searchRequest.addContent(new Element("southBL").setText(_southBL)); - searchRequest.addContent(new Element("eastBL").setText(_eastBL)); - searchRequest.addContent(new Element("westBL").setText(_westBL)); - - Log.debug(Geonet.SEARCH_ENGINE, "RANDOM SEARCH CRITERIA:\n"+ Xml.getString(searchRequest)); - - searcher.search(context, searchRequest, _config); - - Element presentRequest = new Element("request"); - presentRequest.addContent(new Element("fast").setText("true")); - presentRequest.addContent(new Element("from").setText("1")); - presentRequest.addContent(new Element("to").setText(searcher.getSize()+"")); - - List results = searcher.present(context, presentRequest, _config).getChildren(); - - _response = new Element("response"); - for (int i = 0; i < _maxItems && results.size() > 1; i++) - { - Random rnd = new Random(); - int r = rnd.nextInt(results.size() - 1) + 1; // skip summary - - Element mdInfo = (Element)results.remove(r); - mdInfo.detach(); - - Element info = mdInfo.getChild("info", Edit.NAMESPACE); - String id = info.getChildText("id"); - Element md = dataMan.getMetadata(context, id, false); - - _response.addContent(md); + try { + // FIXME: featured should be at metadata level, not at group level + Element searchRequest = new Element("request"); + searchRequest.addContent(new Element(Geonet.SearchResult.BUILD_SUMMARY).setText("false")); + searchRequest.addContent(new Element("featured").setText("true")); + searchRequest.addContent(new Element("relation").setText(_relation)); + searchRequest.addContent(new Element("northBL").setText(_northBL)); + searchRequest.addContent(new Element("southBL").setText(_southBL)); + searchRequest.addContent(new Element("eastBL").setText(_eastBL)); + searchRequest.addContent(new Element("westBL").setText(_westBL)); + + Log.debug(Geonet.SEARCH_ENGINE, "RANDOM SEARCH CRITERIA:\n"+ Xml.getString(searchRequest)); + + searcher.search(context, searchRequest, _config); + + Element presentRequest = new Element("request"); + presentRequest.addContent(new Element("fast").setText("true")); + presentRequest.addContent(new Element("from").setText("1")); + presentRequest.addContent(new Element("to").setText(searcher.getSize()+"")); + + List results = searcher.present(context, presentRequest, _config).getChildren(); + + _response = new Element("response"); + for (int i = 0; i < _maxItems && results.size() > 1; i++) { + Random rnd = new Random(); + int r = rnd.nextInt(results.size() - 1) + 1; // skip summary + + Element mdInfo = (Element)results.remove(r); + mdInfo.detach(); + + Element info = mdInfo.getChild("info", Edit.NAMESPACE); + String id = info.getChildText("id"); + Element md = dataMan.getMetadata(context, id, false); + + _response.addContent(md); + } + _lastUpdateTime = System.currentTimeMillis(); + } finally { + searcher.close(); } - _lastUpdateTime = System.currentTimeMillis(); } return (Element)_response.clone(); } Modified: sandbox/BlueNetMEST/ANZMEST/web/src/main/java/org/fao/geonet/guiservices/metadata/GetRelated.java =================================================================== --- sandbox/BlueNetMEST/ANZMEST/web/src/main/java/org/fao/geonet/guiservices/metadata/GetRelated.java 2011-03-16 14:37:48 UTC (rev 7469) +++ sandbox/BlueNetMEST/ANZMEST/web/src/main/java/org/fao/geonet/guiservices/metadata/GetRelated.java 2011-03-17 05:47:00 UTC (rev 7470) @@ -181,25 +181,30 @@ MetaSearcher searcher = searchMan.newSearcher(SearchManager.LUCENE, Geonet.File.SEARCH_LUCENE); - // Creating parameters for search, fast only to retrieve uuid - Element parameters = new Element(Jeeves.Elem.REQUEST); - if ("children".equals(type)) - parameters.addContent(new Element("parentUuid").setText(uuid)); - else if ("services".equals(type)) - parameters.addContent(new Element("operatesOn").setText(uuid)); - else if ("datasets".equals(type)) - parameters.addContent(new Element("uuid").setText(uuid)); - parameters.addContent(new Element("fast").addContent(fast)); - parameters.addContent(new Element("from").addContent(from)); - parameters.addContent(new Element("to").addContent(to)); + try { + // Creating parameters for search, fast only to retrieve uuid + Element parameters = new Element(Jeeves.Elem.REQUEST); + if ("children".equals(type)) + parameters.addContent(new Element("parentUuid").setText(uuid)); + else if ("services".equals(type)) + parameters.addContent(new Element("operatesOn").setText(uuid)); + else if ("datasets".equals(type)) + parameters.addContent(new Element("uuid").setText(uuid)); + parameters.addContent(new Element("fast").addContent(fast)); + parameters.addContent(new Element("from").addContent(from)); + parameters.addContent(new Element("to").addContent(to)); + + searcher.search(context, parameters, _config); - searcher.search(context, parameters, _config); + Log.info(Geonet.SEARCH_ENGINE, "Getting children search summary"); - Log.info(Geonet.SEARCH_ENGINE, "Getting children search summary"); - - Element response = new Element(type); - Element relatedElement = searcher.present(context, parameters, _config); - response.addContent(relatedElement); - return response; + Element response = new Element(type); + Element relatedElement = searcher.present(context, parameters, _config); + response.addContent(relatedElement); + return response; + } finally { + Log.info(Geonet.SEARCH_ENGINE, "Closing searcher"); + searcher.close(); + } } } Modified: sandbox/BlueNetMEST/ANZMEST/web/src/main/java/org/fao/geonet/kernel/search/LuceneIndexReaderFactory.java =================================================================== --- sandbox/BlueNetMEST/ANZMEST/web/src/main/java/org/fao/geonet/kernel/search/LuceneIndexReaderFactory.java 2011-03-16 14:37:48 UTC (rev 7469) +++ sandbox/BlueNetMEST/ANZMEST/web/src/main/java/org/fao/geonet/kernel/search/LuceneIndexReaderFactory.java 2011-03-17 05:47:00 UTC (rev 7470) @@ -45,7 +45,7 @@ } public synchronized void releaseReader(IndexReader reader) throws IOException { - if (reader.getRefCount() > 1) reader.decRef(); + reader.decRef(); } //=========================================================================== This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |