From: <jes...@us...> - 2012-01-18 16:09:51
|
Revision: 8600 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=8600&view=rev Author: jesseeichar Date: 2012-01-18 16:09:40 +0000 (Wed, 18 Jan 2012) Log Message: ----------- Add guard in IndexMetadataTask so that if an error occurs while indexing the rest of the metadata will be indexed In Transaction add all changed metadata to a Set and index the whole set as one. Guarantees each metadata is indexed only once and all are indexed at the same time. Modified Paths: -------------- trunk/web/src/main/java/org/fao/geonet/kernel/DataManager.java trunk/web/src/main/java/org/fao/geonet/kernel/csw/services/Transaction.java Modified: trunk/web/src/main/java/org/fao/geonet/kernel/DataManager.java =================================================================== --- trunk/web/src/main/java/org/fao/geonet/kernel/DataManager.java 2012-01-18 15:39:44 UTC (rev 8599) +++ trunk/web/src/main/java/org/fao/geonet/kernel/DataManager.java 2012-01-18 16:09:40 UTC (rev 8600) @@ -35,6 +35,7 @@ import jeeves.server.context.ServiceContext; import jeeves.utils.Log; import jeeves.utils.SerialFactory; +import jeeves.utils.Util; import jeeves.utils.Xml; import jeeves.utils.Xml.ErrorHandler; import jeeves.xlink.Processor; @@ -275,7 +276,7 @@ */ public void indexInThreadPool(ServiceContext context, List<String> ids, Dbms dbms) throws SQLException { - dbms.commit(); + if(dbms != null) dbms.commit(); try { GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); @@ -323,7 +324,11 @@ startIndexGroup(); try { for(int i=beginIndex; i<beginIndex+count; i++) { - indexMetadataGroup(dbms, ids.get(i).toString()); + try { + indexMetadataGroup(dbms, ids.get(i).toString()); + } catch (Exception e) { + Log.error(Geonet.INDEX_ENGINE, "Error indexing metadata '"+ids.get(i)+"': "+e.getMessage()+"\n"+ Util.getStackTrace(e)); + } } } finally { endIndexGroup(); Modified: trunk/web/src/main/java/org/fao/geonet/kernel/csw/services/Transaction.java =================================================================== --- trunk/web/src/main/java/org/fao/geonet/kernel/csw/services/Transaction.java 2012-01-18 15:39:44 UTC (rev 8599) +++ trunk/web/src/main/java/org/fao/geonet/kernel/csw/services/Transaction.java 2012-01-18 16:09:40 UTC (rev 8600) @@ -54,6 +54,7 @@ import org.jdom.Namespace; import java.io.File; +import java.sql.SQLException; import java.util.*; //============================================================================= @@ -104,7 +105,12 @@ //process the transaction from the first to the last List<Element> childList = request.getChildren(); - + + GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); + DataManager dataMan = gc.getDataManager(); + + Set<String> toIndex = new HashSet<String>(); + try { //process the childlist @@ -112,31 +118,21 @@ String transactionType = transRequest.getName().toLowerCase(); if (transactionType.equals("insert") || transactionType.equals("update") || transactionType.equals("delete")) { List<Element> mdList = transRequest.getChildren(); - GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); - DataManager dataMan = gc.getDataManager(); // insert to database, and get the number of inserted successful if (transactionType.equals("insert")) { Iterator<Element> inIt = mdList.iterator(); - dataMan.startIndexGroup(); - try { while (inIt.hasNext()) { Element metadata = (Element) inIt.next().clone(); - boolean insertSuccess = insertTransaction(metadata, strFileIds, context); + boolean insertSuccess = insertTransaction(metadata, strFileIds, context, toIndex); if (insertSuccess) { totalInserted++; } } - } - finally { - dataMan.endIndexGroup(); - } } // Update else if (transactionType.equals("update")) { Iterator<Element> inIt = mdList.iterator(); - dataMan.startIndexGroup(); - try { Element metadata = null; while (inIt.hasNext()){ @@ -147,12 +143,7 @@ } } - totalUpdated = updateTransaction( transRequest, metadata, context ); - - } - finally { - dataMan.endIndexGroup(); - } + totalUpdated = updateTransaction( transRequest, metadata, context, toIndex ); } // Delete else { @@ -170,9 +161,14 @@ } finally { - getResponseResult( request, response, strFileIds,totalInserted, totalUpdated, totalDeleted ); - - } + try { + dataMan.indexInThreadPool(context, new ArrayList<String>(toIndex), null); + } catch (SQLException e) { + Log.error(Geonet.CSW, "cannot index"); + Log.error(Geonet.CSW, " (C) StackTrace\n" + Util.getStackTrace(e)); + } + getResponseResult(request, response, strFileIds, totalInserted, totalUpdated, totalDeleted); + } return response; } @@ -198,13 +194,15 @@ //--------------------------------------------------------------------------- /** - * @param xml - * @param fileIds - * @param context - * @return + * + * @param xml + * @param fileIds + * @param context + * @param toIndex + * @return * @throws Exception */ - private boolean insertTransaction( Element xml, List<String> fileIds, ServiceContext context ) throws Exception + private boolean insertTransaction(Element xml, List<String> fileIds, ServiceContext context, Set<String> toIndex) throws Exception { GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); DataManager dataMan = gc.getDataManager(); @@ -262,24 +260,27 @@ dataMan.setOperation(us, dbms, id, "1", AccessManager.OPER_VIEW); } + dataMan.indexMetadataGroup(dbms, id); fileIds.add( uuid ); dbms.commit(); - + toIndex.add(id); return true; } /** - * @param request - * @param xml - * @param context - * @return + * + * @param request + * @param xml + * @param context + * @param toIndex + * @return * @throws Exception */ - private int updateTransaction(Element request, Element xml, ServiceContext context ) throws Exception + private int updateTransaction(Element request, Element xml, ServiceContext context, Set<String> toIndex) throws Exception { GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); DataManager dataMan = gc.getDataManager(); @@ -326,7 +327,8 @@ UserSession session = context.getUserSession(); dataMan.updateMetadata(session, dbms, id, xml, validate, ufo, index, language, changeDate, false); - dataMan.indexMetadataGroup(dbms, id); + dbms.commit(); + toIndex.add(id); totalUpdated++; @@ -348,6 +350,7 @@ Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB); + Set updatedMd = new HashSet<String>(); // Process all records selected while( it.hasNext() ) { @@ -423,13 +426,14 @@ UserSession session = context.getUserSession(); dataMan.updateMetadata(session, dbms, id, metadata, validate, ufo, index, language, changeDate, false); - dataMan.indexMetadataGroup(dbms, id); + updatedMd.add(id); totalUpdated++; } - } + dbms.commit(); + toIndex.addAll(updatedMd); return totalUpdated; @@ -437,12 +441,13 @@ } /** - * @param request - * @param context - * @return + * + * @param request + * @param context + * @return * @throws Exception */ - private int deleteTransaction(Element request, ServiceContext context ) throws Exception + private int deleteTransaction(Element request, ServiceContext context) throws Exception { int deleted = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |