19
19
20
20
/*
21
21
* Copyright (c) 2017, 2020, Chris Fraire <[email protected] >.
22
+ * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
22
23
*/
23
24
package org .opengrok .indexer .index ;
24
25
36
37
import java .time .Duration ;
37
38
import java .time .Instant ;
38
39
import java .util .Comparator ;
39
- import java .util .HashSet ;
40
40
import java .util .List ;
41
41
import java .util .Map ;
42
42
import java .util .Set ;
43
43
import java .util .TreeSet ;
44
+ import java .util .concurrent .ConcurrentHashMap ;
44
45
import java .util .logging .Level ;
45
46
import java .util .logging .Logger ;
46
47
import java .util .stream .Collectors ;
55
56
* be executed.
56
57
* <p>
57
58
* {@link PendingFileCompleter} is not generally thread-safe, as only
58
- * {@link #add(org.opengrok.indexer.index.PendingFileRenaming)} is expected
59
- * to be run in parallel; that method is thread-safe -- but only among other
60
- * callers of the same method.
59
+ * {@link #add(org.opengrok.indexer.index.PendingFileRenaming)},
60
+ * {@link #add(org.opengrok.indexer.index.PendingSymlinkage)} and
61
+ * {@link #add(org.opengrok.indexer.index.PendingFileDeletion)} are expected
62
+ * to be run in parallel; these methods are thread-safe w.r.t. underlying data structures.
61
63
* <p>
62
- * No methods are thread-safe between each other. E.g.,
64
+ * No other methods are thread-safe between each other. E.g.,
63
65
* {@link #complete()} should only be called by a single thread after all
64
66
* additions of {@link PendingSymlinkage}s, {@link PendingFileDeletion}s, and
65
67
* {@link PendingFileRenaming}s are indicated.
66
- * <p>
67
- * {@link #add(org.opengrok.indexer.index.PendingSymlinkage)} should only
68
- * be called in serial from a single thread in an isolated stage.
69
- * <p>
70
- * {@link #add(org.opengrok.indexer.index.PendingFileDeletion)} should only
71
- * be called in serial from a single thread in an isolated stage.
72
- * <p>
73
- * {@link #add(org.opengrok.indexer.index.PendingFileRenaming)}, as noted,
74
- * can be called in parallel in an isolated stage.
75
68
*/
76
69
class PendingFileCompleter {
77
70
@@ -82,10 +75,7 @@ class PendingFileCompleter {
82
75
*/
83
76
public static final String PENDING_EXTENSION = ".org_opengrok" ;
84
77
85
- private static final Logger LOGGER =
86
- LoggerFactory .getLogger (PendingFileCompleter .class );
87
-
88
- private final Object INSTANCE_LOCK = new Object ();
78
+ private static final Logger LOGGER = LoggerFactory .getLogger (PendingFileCompleter .class );
89
79
90
80
private volatile boolean completing ;
91
81
@@ -110,11 +100,11 @@ class PendingFileCompleter {
110
100
return cmp ;
111
101
};
112
102
113
- private final Set <PendingFileDeletion > deletions = new HashSet <> ();
103
+ private final Set <PendingFileDeletion > deletions = ConcurrentHashMap . newKeySet ();
114
104
115
- private final Set <PendingFileRenaming > renames = new HashSet <> ();
105
+ private final Set <PendingFileRenaming > renames = ConcurrentHashMap . newKeySet ();
116
106
117
- private final Set <PendingSymlinkage > linkages = new HashSet <> ();
107
+ private final Set <PendingSymlinkage > linkages = ConcurrentHashMap . newKeySet ();
118
108
119
109
/**
120
110
* Adds the specified element to this instance's set if it is not already
@@ -148,9 +138,7 @@ public boolean add(PendingSymlinkage e) {
148
138
149
139
/**
150
140
* Adds the specified element to this instance's set if it is not already
151
- * present, and also remove any pending deletion for the same absolute
152
- * path -- all in a thread-safe manner among other callers of this same
153
- * method (and only this method).
141
+ * present, and also remove any pending deletion for the same absolute path.
154
142
* @param e element to be added to this set
155
143
* @return {@code true} if this instance's set did not already contain the
156
144
* specified element
@@ -160,11 +148,9 @@ public boolean add(PendingFileRenaming e) {
160
148
if (completing ) {
161
149
throw new IllegalStateException ("complete() is running" );
162
150
}
163
- synchronized (INSTANCE_LOCK ) {
164
- boolean rc = renames .add (e );
165
- deletions .remove (new PendingFileDeletion (e .getAbsolutePath ()));
166
- return rc ;
167
- }
151
+ boolean rc = renames .add (e );
152
+ deletions .remove (new PendingFileDeletion (e .getAbsolutePath ()));
153
+ return rc ;
168
154
}
169
155
170
156
/**
0 commit comments