@@ -441,21 +441,27 @@ private CloseableRandomVectorScorerSupplier mergeOneFieldToIndex(
441441 float cDotC
442442 ) throws IOException {
443443 long vectorDataOffset = binarizedVectorData .alignFilePointer (Float .BYTES );
444- final IndexOutput tempQuantizedVectorData = segmentWriteState .directory .createTempOutput (
445- binarizedVectorData .getName (),
446- "temp" ,
447- segmentWriteState .context
448- );
449- final IndexOutput tempScoreQuantizedVectorData = segmentWriteState .directory .createTempOutput (
450- binarizedVectorData .getName (),
451- "score_temp" ,
452- segmentWriteState .context
453- );
454444 IndexInput binarizedDataInput = null ;
455445 IndexInput binarizedScoreDataInput = null ;
446+ IndexOutput tempQuantizedVectorData = null ;
447+ IndexOutput tempScoreQuantizedVectorData = null ;
456448 boolean success = false ;
457449 OptimizedScalarQuantizer quantizer = new OptimizedScalarQuantizer (fieldInfo .getVectorSimilarityFunction ());
458450 try {
451+ // Since we are opening two files, it's possible that one or the other fails to open
452+ // we open them within the try to ensure they are cleaned
453+ tempQuantizedVectorData = segmentWriteState .directory .createTempOutput (
454+ binarizedVectorData .getName (),
455+ "temp" ,
456+ segmentWriteState .context
457+ );
458+ tempScoreQuantizedVectorData = segmentWriteState .directory .createTempOutput (
459+ binarizedVectorData .getName (),
460+ "score_temp" ,
461+ segmentWriteState .context
462+ );
463+ final String tempQuantizedVectorDataName = tempQuantizedVectorData .getName ();
464+ final String tempScoreQuantizedVectorDataName = tempScoreQuantizedVectorData .getName ();
459465 FloatVectorValues floatVectorValues = KnnVectorsWriter .MergedVectorValues .mergeFloatVectorValues (fieldInfo , mergeState );
460466 if (fieldInfo .getVectorSimilarityFunction () == COSINE ) {
461467 floatVectorValues = new NormalizedFloatVectorValues (floatVectorValues );
@@ -514,8 +520,8 @@ private CloseableRandomVectorScorerSupplier mergeOneFieldToIndex(
514520 IOUtils .close (finalBinarizedDataInput , finalBinarizedScoreDataInput );
515521 IOUtils .deleteFilesIgnoringExceptions (
516522 segmentWriteState .directory ,
517- tempQuantizedVectorData . getName () ,
518- tempScoreQuantizedVectorData . getName ()
523+ tempQuantizedVectorDataName ,
524+ tempScoreQuantizedVectorDataName
519525 );
520526 });
521527 } finally {
@@ -526,11 +532,12 @@ private CloseableRandomVectorScorerSupplier mergeOneFieldToIndex(
526532 binarizedDataInput ,
527533 binarizedScoreDataInput
528534 );
529- IOUtils .deleteFilesIgnoringExceptions (
530- segmentWriteState .directory ,
531- tempQuantizedVectorData .getName (),
532- tempScoreQuantizedVectorData .getName ()
533- );
535+ if (tempQuantizedVectorData != null ) {
536+ IOUtils .deleteFilesIgnoringExceptions (segmentWriteState .directory , tempQuantizedVectorData .getName ());
537+ }
538+ if (tempScoreQuantizedVectorData != null ) {
539+ IOUtils .deleteFilesIgnoringExceptions (segmentWriteState .directory , tempScoreQuantizedVectorData .getName ());
540+ }
534541 }
535542 }
536543 }
0 commit comments