19
19
20
20
/*
21
21
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
22
+ * Portions Copyright (c) 2017, Chris Fraire <[email protected] >.
22
23
*/
23
24
package org .opensolaris .opengrok .index ;
24
25
@@ -376,6 +377,7 @@ public void update() throws IOException, HistoryException {
376
377
}
377
378
}
378
379
380
+ IOException writerException = null ;
379
381
try {
380
382
Analyzer analyzer = AnalyzerGuru .getAnalyzer ();
381
383
IndexWriterConfig iwc = new IndexWriterConfig (analyzer );
@@ -447,31 +449,43 @@ public void update() throws IOException, HistoryException {
447
449
reader .close ();
448
450
}
449
451
}
452
+
453
+ try {
454
+ writer .commit ();
455
+ } catch (IOException e ) {
456
+ writerException = e ;
457
+ LOGGER .log (Level .WARNING ,
458
+ "An error occured while committing writer" , e );
459
+ }
450
460
} finally {
451
- if (writer != null ) {
452
- try {
453
- writer .prepareCommit ();
454
- writer .commit ();
455
- writer .close ();
456
- } catch (IOException e ) {
457
- LOGGER .log (Level .WARNING , "An error occured while closing writer" , e );
461
+ Ctags finishingCtags = ctags ;
462
+ ctags = null ;
463
+
464
+ try {
465
+ if (writer != null ) writer .close ();
466
+ } catch (IOException e ) {
467
+ if (writerException == null ) writerException = e ;
468
+ LOGGER .log (Level .WARNING ,
469
+ "An error occured while closing writer" , e );
470
+ } finally {
471
+ writer = null ;
472
+ synchronized (lock ) {
473
+ running = false ;
458
474
}
459
475
}
460
476
461
- if (ctags != null ) {
477
+ if (finishingCtags != null ) {
462
478
try {
463
- ctags .close ();
479
+ finishingCtags .close ();
464
480
} catch (IOException e ) {
465
481
LOGGER .log (Level .WARNING ,
466
482
"An error occured while closing ctags process" , e );
467
483
}
468
484
}
469
-
470
- synchronized (lock ) {
471
- running = false ;
472
- }
473
485
}
474
486
487
+ if (writerException != null ) throw writerException ;
488
+
475
489
if (!isInterrupted () && isDirty ()) {
476
490
if (env .isOptimizeDatabase ()) {
477
491
optimize ();
@@ -518,15 +532,17 @@ public void run() {
518
532
/**
519
533
* Optimize the index database
520
534
*/
521
- public void optimize () {
535
+ public void optimize () throws IOException {
522
536
synchronized (lock ) {
523
537
if (running ) {
524
538
LOGGER .warning ("Optimize terminated... Someone else is updating / optimizing it!" );
525
539
return ;
526
540
}
527
541
running = true ;
528
542
}
543
+
529
544
IndexWriter wrt = null ;
545
+ IOException writerException = null ;
530
546
try {
531
547
LOGGER .info ("Optimizing the index ... " );
532
548
Analyzer analyzer = new StandardAnalyzer ();
@@ -544,12 +560,14 @@ public void optimize() {
544
560
dirty = false ;
545
561
}
546
562
} catch (IOException e ) {
563
+ writerException = e ;
547
564
LOGGER .log (Level .SEVERE , "ERROR: optimizing index: {0}" , e );
548
565
} finally {
549
566
if (wrt != null ) {
550
567
try {
551
568
wrt .close ();
552
569
} catch (IOException e ) {
570
+ if (writerException == null ) writerException = e ;
553
571
LOGGER .log (Level .WARNING ,
554
572
"An error occured while closing writer" , e );
555
573
}
@@ -558,6 +576,8 @@ public void optimize() {
558
576
running = false ;
559
577
}
560
578
}
579
+
580
+ if (writerException != null ) throw writerException ;
561
581
}
562
582
563
583
private boolean isDirty () {
0 commit comments