10
10
11
11
import java .nio .file .Path ;
12
12
import java .util .*;
13
+ import java .util .concurrent .ConcurrentHashMap ;
13
14
import java .util .stream .Collectors ;
14
15
15
16
@ Slf4j
@@ -28,6 +29,9 @@ public class PublishManager {
28
29
// Used to check if symlink target is already published
29
30
private final Map <Path , Set <Path >> publishMap = new HashMap <>();
30
31
private final PublishExecHolder execHolder = new PublishExecHolder ();
32
+ private final Map <NodeLocation , Integer > currentPublishJobsPerNode = new ConcurrentHashMap <>();
33
+ // Maximum number of parallel publish jobs per node
34
+ private final int MAX_COPY_PER_NODE = 1 ;
31
35
32
36
/**
33
37
* Maximum number of arguments for the publish command.
@@ -176,6 +180,7 @@ private void publishFiles( List<FileWrapper> items, NodeLocation node ) {
176
180
}
177
181
execHolder .finishedOnNode ( node );
178
182
};
183
+ currentPublishJobsPerNode .compute ( node , ( k , v ) -> v == null ? 1 : v + 1 );
179
184
final PublishListener publishListener = new PublishListener ( scheduler , name , onFinish );
180
185
execHolder .addRunnable ( node , () ->
181
186
client .execCommand ( daemonName , scheduler .getNamespace (), command , publishListener )
@@ -215,7 +220,7 @@ private void createSymlinksIntern( final Symlink[] symlinks, final int start, in
215
220
216
221
String name = "Copying from node: " + node ;
217
222
final String daemonName = scheduler .getDaemonNameOnNode ( node );
218
- final Runnable onFinish = new InformPublishFinishedRunnable ( execHolder , location );
223
+ final Runnable onFinish = new InformPublishFinishedRunnable ( execHolder , location , currentPublishJobsPerNode );
219
224
final PublishListener publishListener = new PublishListener ( scheduler , name , onFinish );
220
225
execHolder .addRunnable ( location , () ->
221
226
client .execCommand ( daemonName , scheduler .getNamespace (), command , publishListener )
@@ -242,7 +247,9 @@ private void publishFirstX( final Map<NodeLocation, LinkedList<FileWrapper>> nod
242
247
for ( Map .Entry <NodeLocation , LinkedList <FileWrapper >> entry : nodeItemsMap .entrySet () ) {
243
248
final NodeLocation node = entry .getKey ();
244
249
LinkedList <FileWrapper > items = entry .getValue ();
245
- while ( currentlyCopyingTasksOnNode .getOrDefault ( node , 0 ) < maxCopyPerNode && items != null && !items .isEmpty () ) {
250
+ while ( currentPublishJobsPerNode .getOrDefault ( node , 0 ) < MAX_COPY_PER_NODE
251
+ && currentlyCopyingTasksOnNode .getOrDefault ( node , 0 ) < maxCopyPerNode
252
+ && items != null && !items .isEmpty () ) {
246
253
currentlyCopyingTasksOnNode .compute ( node , ( k , v ) -> v == null ? 1 : v + 1 );
247
254
publishFiles ( removeUntil ( items , maxSize ), node );
248
255
}
0 commit comments