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
+ * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
23
23
*/
24
24
package org .opengrok .indexer .index ;
25
25
62
62
* to be run in parallel; these methods are thread-safe w.r.t. underlying data structures.
63
63
* <p>
64
64
* No other methods are thread-safe between each other. E.g.,
65
- * {@link #complete()} should only be called by a single thread after all
65
+ * {@link #complete(String )} should only be called by a single thread after all
66
66
* additions of {@link PendingSymlinkage}s, {@link PendingFileDeletion}s, and
67
67
* {@link PendingFileRenaming}s are indicated.
68
68
*/
@@ -112,7 +112,7 @@ class PendingFileCompleter {
112
112
* @param e element to be added to this set
113
113
* @return {@code true} if this instance's set did not already contain the
114
114
* specified element
115
- * @throws IllegalStateException if {@link #complete()} is running
115
+ * @throws IllegalStateException if {@link #complete(String )} is running
116
116
*/
117
117
public boolean add (PendingFileDeletion e ) {
118
118
if (completing ) {
@@ -127,7 +127,7 @@ public boolean add(PendingFileDeletion e) {
127
127
* @param e element to be added to this set
128
128
* @return {@code true} if this instance's set did not already contain the
129
129
* specified element
130
- * @throws IllegalStateException if {@link #complete()} is running
130
+ * @throws IllegalStateException if {@link #complete(String )} is running
131
131
*/
132
132
public boolean add (PendingSymlinkage e ) {
133
133
if (completing ) {
@@ -142,7 +142,7 @@ public boolean add(PendingSymlinkage e) {
142
142
* @param e element to be added to this set
143
143
* @return {@code true} if this instance's set did not already contain the
144
144
* specified element
145
- * @throws IllegalStateException if {@link #complete()} is running
145
+ * @throws IllegalStateException if {@link #complete(String )} is running
146
146
*/
147
147
public boolean add (PendingFileRenaming e ) {
148
148
if (completing ) {
@@ -166,40 +166,41 @@ public boolean add(PendingFileRenaming e) {
166
166
* {@link PendingFileDeletion#getAbsolutePath()}; for a version of the path
167
167
* with {@link #PENDING_EXTENSION} appended; and also for the path's parent
168
168
* directory, which does nothing if the directory is not empty.
169
+ * @param logSuffix suffix to use when logging
169
170
* @return the number of successful operations
170
171
* @throws java.io.IOException if an I/O error occurs
171
172
*/
172
- public int complete () throws IOException {
173
+ public int complete (String logSuffix ) throws IOException {
173
174
completing = true ;
174
175
try {
175
- return completeInner ();
176
+ return completeInner (logSuffix );
176
177
} finally {
177
178
completing = false ;
178
179
}
179
180
}
180
181
181
- private int completeInner () throws IOException {
182
+ private int completeInner (String logSuffix ) throws IOException {
182
183
Instant start = Instant .now ();
183
- int numDeletions = completeDeletions ();
184
+ int numDeletions = completeDeletions (logSuffix );
184
185
if (LOGGER .isLoggable (Level .FINE )) {
185
- LOGGER .log (Level .FINE , "deleted {0} file(s) (took {1 })" ,
186
- new Object [] {numDeletions , StringUtils .getReadableTime (
186
+ LOGGER .log (Level .FINE , "deleted {0} file(s){1} (took {2 })" ,
187
+ new Object [] {numDeletions , logSuffix , StringUtils .getReadableTime (
187
188
Duration .between (start , Instant .now ()).toMillis ())});
188
189
}
189
190
190
191
start = Instant .now ();
191
- int numRenamings = completeRenamings ();
192
+ int numRenamings = completeRenamings (logSuffix );
192
193
if (LOGGER .isLoggable (Level .FINE )) {
193
- LOGGER .log (Level .FINE , "renamed {0} file(s) (took {1 })" ,
194
- new Object [] {numRenamings , StringUtils .getReadableTime (
194
+ LOGGER .log (Level .FINE , "renamed {0} file(s){1} (took {2 })" ,
195
+ new Object [] {numRenamings , logSuffix , StringUtils .getReadableTime (
195
196
Duration .between (start , Instant .now ()).toMillis ())});
196
197
}
197
198
198
199
start = Instant .now ();
199
- int numLinkages = completeLinkages ();
200
+ int numLinkages = completeLinkages (logSuffix );
200
201
if (LOGGER .isLoggable (Level .FINE )) {
201
- LOGGER .log (Level .FINE , "affirmed links for {0} path(s) (took {1 })" ,
202
- new Object [] {numLinkages , StringUtils .getReadableTime (
202
+ LOGGER .log (Level .FINE , "affirmed links for {0} path(s){1} (took {2 })" ,
203
+ new Object [] {numLinkages , logSuffix , StringUtils .getReadableTime (
203
204
Duration .between (start , Instant .now ()).toMillis ())});
204
205
}
205
206
@@ -209,9 +210,10 @@ private int completeInner() throws IOException {
209
210
/**
210
211
* Attempts to rename all the tracked elements, catching any failures, and
211
212
* throwing an exception if any failed.
213
+ * @param logSuffix suffix to use when logging
212
214
* @return the number of successful renamings
213
215
*/
214
- private int completeRenamings () throws IOException {
216
+ private int completeRenamings (String logSuffix ) throws IOException {
215
217
int numPending = renames .size ();
216
218
int numFailures = 0 ;
217
219
@@ -226,7 +228,7 @@ private int completeRenamings() throws IOException {
226
228
Collectors .toList ());
227
229
Map <Boolean , List <PendingFileRenamingExec >> bySuccess ;
228
230
229
- try (Progress progress = new Progress (LOGGER , "pending renames" , numPending )) {
231
+ try (Progress progress = new Progress (LOGGER , String . format ( "pending renames%s" , logSuffix ) , numPending )) {
230
232
bySuccess = pendingExecs .parallelStream ().collect (
231
233
Collectors .groupingByConcurrent ((x ) -> {
232
234
progress .increment ();
@@ -247,8 +249,8 @@ private int completeRenamings() throws IOException {
247
249
numFailures = failures .size ();
248
250
double pctFailed = 100.0 * numFailures / numPending ;
249
251
String exmsg = String .format (
250
- "%d failures (%.1f%%) while renaming pending files" ,
251
- numFailures , pctFailed );
252
+ "%d failures (%.1f%%) while renaming pending files%s " ,
253
+ numFailures , pctFailed , logSuffix );
252
254
throw new IOException (exmsg , failures .get (0 ).exception );
253
255
}
254
256
@@ -258,9 +260,10 @@ private int completeRenamings() throws IOException {
258
260
/**
259
261
* Attempts to delete all the tracked elements, catching any failures, and
260
262
* throwing an exception if any failed.
263
+ * @param logSuffix suffix to use when logging
261
264
* @return the number of successful deletions
262
265
*/
263
- private int completeDeletions () throws IOException {
266
+ private int completeDeletions (String logSuffix ) throws IOException {
264
267
int numPending = deletions .size ();
265
268
int numFailures = 0 ;
266
269
@@ -274,7 +277,7 @@ private int completeDeletions() throws IOException {
274
277
Collectors .toList ());
275
278
Map <Boolean , List <PendingFileDeletionExec >> bySuccess ;
276
279
277
- try (Progress progress = new Progress (LOGGER , "pending deletions" , numPending )) {
280
+ try (Progress progress = new Progress (LOGGER , String . format ( "pending deletions%s" , logSuffix ) , numPending )) {
278
281
bySuccess = pendingExecs .parallelStream ().collect (
279
282
Collectors .groupingByConcurrent ((x ) -> {
280
283
progress .increment ();
@@ -296,8 +299,8 @@ private int completeDeletions() throws IOException {
296
299
numFailures = failures .size ();
297
300
double pctFailed = 100.0 * numFailures / numPending ;
298
301
String exmsg = String .format (
299
- "%d failures (%.1f%%) while deleting pending files" ,
300
- numFailures , pctFailed );
302
+ "%d failures (%.1f%%) while deleting pending files%s " ,
303
+ numFailures , pctFailed , logSuffix );
301
304
throw new IOException (exmsg , failures .get (0 ).exception );
302
305
}
303
306
@@ -307,9 +310,10 @@ private int completeDeletions() throws IOException {
307
310
/**
308
311
* Attempts to link the tracked elements, catching any failures, and
309
312
* throwing an exception if any failed.
313
+ * @param logSuffix suffix to use when logging
310
314
* @return the number of successful linkages
311
315
*/
312
- private int completeLinkages () throws IOException {
316
+ private int completeLinkages (String logSuffix ) throws IOException {
313
317
int numPending = linkages .size ();
314
318
int numFailures = 0 ;
315
319
@@ -323,7 +327,7 @@ private int completeLinkages() throws IOException {
323
327
f .getTargetRelPath ())).collect (Collectors .toList ());
324
328
325
329
Map <Boolean , List <PendingSymlinkageExec >> bySuccess ;
326
- try (Progress progress = new Progress (LOGGER , "pending linkages" , numPending )) {
330
+ try (Progress progress = new Progress (LOGGER , String . format ( "pending linkages%s" , logSuffix ) , numPending )) {
327
331
bySuccess = pendingExecs .parallelStream ().collect (
328
332
Collectors .groupingByConcurrent ((x ) -> {
329
333
progress .increment ();
@@ -344,8 +348,8 @@ private int completeLinkages() throws IOException {
344
348
numFailures = failures .size ();
345
349
double pctFailed = 100.0 * numFailures / numPending ;
346
350
String exmsg = String .format (
347
- "%d failures (%.1f%%) while linking pending paths" ,
348
- numFailures , pctFailed );
351
+ "%d failures (%.1f%%) while linking pending paths%s " ,
352
+ numFailures , pctFailed , logSuffix );
349
353
throw new IOException (exmsg , failures .get (0 ).exception );
350
354
}
351
355
0 commit comments