Skip to content

Commit d9d93cd

Browse files
committed
log project
1 parent 6836396 commit d9d93cd

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public class IndexDatabase {
150150
private final Map<String, IndexedSymlink> indexedSymlinks = new TreeMap<>(
151151
Comparator.comparingInt(String::length).thenComparing(o -> o));
152152

153+
@Nullable
153154
private final Project project;
154155
private FSDirectory indexDirectory;
155156
private IndexReader reader;
@@ -2125,7 +2126,7 @@ private void finishWriting() throws IOException {
21252126
hasPendingCommit = true;
21262127

21272128
Statistics completerStat = new Statistics();
2128-
int n = completer.complete();
2129+
int n = completer.complete(this.project != null ? " for project " + this.project : "");
21292130
completerStat.report(LOGGER, Level.FINE, String.format("completed %d object(s)", n));
21302131

21312132
// Just before commit(), reset the `hasPendingCommit' flag,
@@ -2144,7 +2145,7 @@ private void finishWriting() throws IOException {
21442145
}
21452146

21462147
/**
2147-
* Verify TABSIZE, and evaluate AnalyzerGuru version together with ZVER --
2148+
* Verify {@code TABSIZE}, and evaluate AnalyzerGuru version together with {@code ZVER} --
21482149
* or return a value to indicate mismatch.
21492150
* @param file the source file object
21502151
* @param path the source file path

opengrok-indexer/src/main/java/org/opengrok/indexer/index/PendingFileCompleter.java

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* 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.
2323
*/
2424
package org.opengrok.indexer.index;
2525

@@ -62,7 +62,7 @@
6262
* to be run in parallel; these methods are thread-safe w.r.t. underlying data structures.
6363
* <p>
6464
* 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
6666
* additions of {@link PendingSymlinkage}s, {@link PendingFileDeletion}s, and
6767
* {@link PendingFileRenaming}s are indicated.
6868
*/
@@ -112,7 +112,7 @@ class PendingFileCompleter {
112112
* @param e element to be added to this set
113113
* @return {@code true} if this instance's set did not already contain the
114114
* specified element
115-
* @throws IllegalStateException if {@link #complete()} is running
115+
* @throws IllegalStateException if {@link #complete(String)} is running
116116
*/
117117
public boolean add(PendingFileDeletion e) {
118118
if (completing) {
@@ -127,7 +127,7 @@ public boolean add(PendingFileDeletion e) {
127127
* @param e element to be added to this set
128128
* @return {@code true} if this instance's set did not already contain the
129129
* specified element
130-
* @throws IllegalStateException if {@link #complete()} is running
130+
* @throws IllegalStateException if {@link #complete(String)} is running
131131
*/
132132
public boolean add(PendingSymlinkage e) {
133133
if (completing) {
@@ -142,7 +142,7 @@ public boolean add(PendingSymlinkage e) {
142142
* @param e element to be added to this set
143143
* @return {@code true} if this instance's set did not already contain the
144144
* specified element
145-
* @throws IllegalStateException if {@link #complete()} is running
145+
* @throws IllegalStateException if {@link #complete(String)} is running
146146
*/
147147
public boolean add(PendingFileRenaming e) {
148148
if (completing) {
@@ -166,40 +166,41 @@ public boolean add(PendingFileRenaming e) {
166166
* {@link PendingFileDeletion#getAbsolutePath()}; for a version of the path
167167
* with {@link #PENDING_EXTENSION} appended; and also for the path's parent
168168
* directory, which does nothing if the directory is not empty.
169+
* @param logSuffix suffix to use when logging
169170
* @return the number of successful operations
170171
* @throws java.io.IOException if an I/O error occurs
171172
*/
172-
public int complete() throws IOException {
173+
public int complete(String logSuffix) throws IOException {
173174
completing = true;
174175
try {
175-
return completeInner();
176+
return completeInner(logSuffix);
176177
} finally {
177178
completing = false;
178179
}
179180
}
180181

181-
private int completeInner() throws IOException {
182+
private int completeInner(String logSuffix) throws IOException {
182183
Instant start = Instant.now();
183-
int numDeletions = completeDeletions();
184+
int numDeletions = completeDeletions(logSuffix);
184185
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(
187188
Duration.between(start, Instant.now()).toMillis())});
188189
}
189190

190191
start = Instant.now();
191-
int numRenamings = completeRenamings();
192+
int numRenamings = completeRenamings(logSuffix);
192193
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(
195196
Duration.between(start, Instant.now()).toMillis())});
196197
}
197198

198199
start = Instant.now();
199-
int numLinkages = completeLinkages();
200+
int numLinkages = completeLinkages(logSuffix);
200201
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(
203204
Duration.between(start, Instant.now()).toMillis())});
204205
}
205206

@@ -209,9 +210,10 @@ private int completeInner() throws IOException {
209210
/**
210211
* Attempts to rename all the tracked elements, catching any failures, and
211212
* throwing an exception if any failed.
213+
* @param logSuffix suffix to use when logging
212214
* @return the number of successful renamings
213215
*/
214-
private int completeRenamings() throws IOException {
216+
private int completeRenamings(String logSuffix) throws IOException {
215217
int numPending = renames.size();
216218
int numFailures = 0;
217219

@@ -226,7 +228,7 @@ private int completeRenamings() throws IOException {
226228
Collectors.toList());
227229
Map<Boolean, List<PendingFileRenamingExec>> bySuccess;
228230

229-
try (Progress progress = new Progress(LOGGER, "pending renames", numPending)) {
231+
try (Progress progress = new Progress(LOGGER, String.format("pending renames%s", logSuffix), numPending)) {
230232
bySuccess = pendingExecs.parallelStream().collect(
231233
Collectors.groupingByConcurrent((x) -> {
232234
progress.increment();
@@ -247,8 +249,8 @@ private int completeRenamings() throws IOException {
247249
numFailures = failures.size();
248250
double pctFailed = 100.0 * numFailures / numPending;
249251
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);
252254
throw new IOException(exmsg, failures.get(0).exception);
253255
}
254256

@@ -258,9 +260,10 @@ private int completeRenamings() throws IOException {
258260
/**
259261
* Attempts to delete all the tracked elements, catching any failures, and
260262
* throwing an exception if any failed.
263+
* @param logSuffix suffix to use when logging
261264
* @return the number of successful deletions
262265
*/
263-
private int completeDeletions() throws IOException {
266+
private int completeDeletions(String logSuffix) throws IOException {
264267
int numPending = deletions.size();
265268
int numFailures = 0;
266269

@@ -274,7 +277,7 @@ private int completeDeletions() throws IOException {
274277
Collectors.toList());
275278
Map<Boolean, List<PendingFileDeletionExec>> bySuccess;
276279

277-
try (Progress progress = new Progress(LOGGER, "pending deletions", numPending)) {
280+
try (Progress progress = new Progress(LOGGER, String.format("pending deletions%s", logSuffix), numPending)) {
278281
bySuccess = pendingExecs.parallelStream().collect(
279282
Collectors.groupingByConcurrent((x) -> {
280283
progress.increment();
@@ -296,8 +299,8 @@ private int completeDeletions() throws IOException {
296299
numFailures = failures.size();
297300
double pctFailed = 100.0 * numFailures / numPending;
298301
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);
301304
throw new IOException(exmsg, failures.get(0).exception);
302305
}
303306

@@ -307,9 +310,10 @@ private int completeDeletions() throws IOException {
307310
/**
308311
* Attempts to link the tracked elements, catching any failures, and
309312
* throwing an exception if any failed.
313+
* @param logSuffix suffix to use when logging
310314
* @return the number of successful linkages
311315
*/
312-
private int completeLinkages() throws IOException {
316+
private int completeLinkages(String logSuffix) throws IOException {
313317
int numPending = linkages.size();
314318
int numFailures = 0;
315319

@@ -323,7 +327,7 @@ private int completeLinkages() throws IOException {
323327
f.getTargetRelPath())).collect(Collectors.toList());
324328

325329
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)) {
327331
bySuccess = pendingExecs.parallelStream().collect(
328332
Collectors.groupingByConcurrent((x) -> {
329333
progress.increment();
@@ -344,8 +348,8 @@ private int completeLinkages() throws IOException {
344348
numFailures = failures.size();
345349
double pctFailed = 100.0 * numFailures / numPending;
346350
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);
349353
throw new IOException(exmsg, failures.get(0).exception);
350354
}
351355

0 commit comments

Comments
 (0)