From: Olivier Lamy Date: Tue, 17 Dec 2013 07:29:40 +0000 (+0000) Subject: prevent running in parrallel X-Git-Tag: archiva-2.0.0-RC1~90 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d5830c882e5d5c89aacf52522d3e496645a6583a;p=archiva.git prevent running in parrallel git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1551476 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java index 4a939cb49..68ab59791 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java @@ -65,6 +65,8 @@ public class DefaultIndexMerger private List temporaryGroupIndexes = new CopyOnWriteArrayList(); + private List runningGroups = new CopyOnWriteArrayList(); + @Inject public DefaultIndexMerger( PlexusSisuBridge plexusSisuBridge, MavenIndexerUtils mavenIndexerUtils ) throws PlexusSisuBridgeException @@ -77,19 +79,29 @@ public class DefaultIndexMerger public IndexingContext buildMergedIndex( IndexMergerRequest indexMergerRequest ) throws IndexMergerException { + String groupId = indexMergerRequest.getGroupId(); + + if ( runningGroups.contains( groupId ) ) + { + log.info( "skip build merge remote indexes for id: '{}' as already running", groupId ); + return null; + } + + runningGroups.add( groupId ); + StopWatch stopWatch = new StopWatch(); stopWatch.reset(); stopWatch.start(); - File tempRepoFile = indexMergerRequest.getMergedIndexDirectory(); + File mergedIndexDirectory = indexMergerRequest.getMergedIndexDirectory(); - String tempRepoId = tempRepoFile.getName(); + String tempRepoId = mergedIndexDirectory.getName(); try { - File indexLocation = new File( tempRepoFile, indexMergerRequest.getMergedIndexPath() ); + File indexLocation = new File( mergedIndexDirectory, indexMergerRequest.getMergedIndexPath() ); IndexingContext indexingContext = - indexer.addIndexingContext( tempRepoId, tempRepoId, tempRepoFile, indexLocation, null, null, + indexer.addIndexingContext( tempRepoId, tempRepoId, mergedIndexDirectory, indexLocation, null, null, mavenIndexerUtils.getAllIndexCreators() ); for ( String repoId : indexMergerRequest.getRepositoriesIds() ) @@ -108,8 +120,8 @@ public class DefaultIndexMerger IndexPackingRequest request = new IndexPackingRequest( indexingContext, indexLocation ); indexPacker.packIndex( request ); } - temporaryGroupIndexes.add( - new TemporaryGroupIndex( tempRepoFile, tempRepoId, indexMergerRequest.getGroupId(), indexMergerRequest.getMergedIndexTtl() ) ); + temporaryGroupIndexes.add( new TemporaryGroupIndex( mergedIndexDirectory, tempRepoId, groupId, + indexMergerRequest.getMergedIndexTtl() ) ); stopWatch.stop(); log.info( "merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(), stopWatch.getTime() ); @@ -123,6 +135,10 @@ public class DefaultIndexMerger { throw new IndexMergerException( e.getMessage(), e ); } + finally + { + runningGroups.remove( groupId ); + } } @Async