@@ -443,21 +443,27 @@ private CloseableRandomVectorScorerSupplier mergeOneFieldToIndex(
443443 float cDotC
444444 ) throws IOException {
445445 long vectorDataOffset = binarizedVectorData .alignFilePointer (Float .BYTES );
446- final IndexOutput tempQuantizedVectorData = segmentWriteState .directory .createTempOutput (
447- binarizedVectorData .getName (),
448- "temp" ,
449- segmentWriteState .context
450- );
451- final IndexOutput tempScoreQuantizedVectorData = segmentWriteState .directory .createTempOutput (
452- binarizedVectorData .getName (),
453- "score_temp" ,
454- segmentWriteState .context
455- );
456446 IndexInput binarizedDataInput = null ;
457447 IndexInput binarizedScoreDataInput = null ;
448+ IndexOutput tempQuantizedVectorData = null ;
449+ IndexOutput tempScoreQuantizedVectorData = null ;
458450 boolean success = false ;
459451 OptimizedScalarQuantizer quantizer = new OptimizedScalarQuantizer (fieldInfo .getVectorSimilarityFunction ());
460452 try {
453+ // Since we are opening two files, it's possible that one or the other fails to open
454+ // we open them within the try to ensure they are cleaned
455+ tempQuantizedVectorData = segmentWriteState .directory .createTempOutput (
456+ binarizedVectorData .getName (),
457+ "temp" ,
458+ segmentWriteState .context
459+ );
460+ tempScoreQuantizedVectorData = segmentWriteState .directory .createTempOutput (
461+ binarizedVectorData .getName (),
462+ "score_temp" ,
463+ segmentWriteState .context
464+ );
465+ final String tempQuantizedVectorDataName = tempQuantizedVectorData .getName ();
466+ final String tempScoreQuantizedVectorDataName = tempScoreQuantizedVectorData .getName ();
461467 FloatVectorValues floatVectorValues = KnnVectorsWriter .MergedVectorValues .mergeFloatVectorValues (fieldInfo , mergeState );
462468 if (fieldInfo .getVectorSimilarityFunction () == COSINE ) {
463469 floatVectorValues = new NormalizedFloatVectorValues (floatVectorValues );
@@ -516,8 +522,8 @@ private CloseableRandomVectorScorerSupplier mergeOneFieldToIndex(
516522 IOUtils .close (finalBinarizedDataInput , finalBinarizedScoreDataInput );
517523 IOUtils .deleteFilesIgnoringExceptions (
518524 segmentWriteState .directory ,
519- tempQuantizedVectorData . getName () ,
520- tempScoreQuantizedVectorData . getName ()
525+ tempQuantizedVectorDataName ,
526+ tempScoreQuantizedVectorDataName
521527 );
522528 });
523529 } finally {
@@ -528,11 +534,12 @@ private CloseableRandomVectorScorerSupplier mergeOneFieldToIndex(
528534 binarizedDataInput ,
529535 binarizedScoreDataInput
530536 );
531- IOUtils .deleteFilesIgnoringExceptions (
532- segmentWriteState .directory ,
533- tempQuantizedVectorData .getName (),
534- tempScoreQuantizedVectorData .getName ()
535- );
537+ if (tempQuantizedVectorData != null ) {
538+ IOUtils .deleteFilesIgnoringExceptions (segmentWriteState .directory , tempQuantizedVectorData .getName ());
539+ }
540+ if (tempScoreQuantizedVectorData != null ) {
541+ IOUtils .deleteFilesIgnoringExceptions (segmentWriteState .directory , tempScoreQuantizedVectorData .getName ());
542+ }
536543 }
537544 }
538545 }
0 commit comments