@@ -670,20 +670,13 @@ private IndexResult innerIndex(Index index) throws IOException {
670670 final IndexResult indexResult ;
671671 if (checkVersionConflictResult .isPresent ()) {
672672 indexResult = checkVersionConflictResult .get ();
673- // norelease: this is not correct as this does not force an fsync, and we need to handle failures including replication
674- if (indexResult .hasFailure () || seqNo == SequenceNumbersService .UNASSIGNED_SEQ_NO ) {
675- location = null ;
676- } else {
677- final Translog .NoOp operation = new Translog .NoOp (seqNo , index .primaryTerm (), "version conflict during recovery" );
678- location = index .origin () != Operation .Origin .LOCAL_TRANSLOG_RECOVERY ? translog .add (operation ) : null ;
679- }
680673 } else {
681674 // no version conflict
682675 if (index .origin () == Operation .Origin .PRIMARY ) {
683676 seqNo = seqNoService ().generateSeqNo ();
684677 }
685678
686- /*
679+ /**
687680 * Update the document's sequence number and primary term; the sequence number here is derived here from either the sequence
688681 * number service if this is on the primary, or the existing document's sequence number if this is on the replica. The
689682 * primary term here has already been set, see IndexShard#prepareIndex where the Engine$Index operation is created.
@@ -700,11 +693,12 @@ private IndexResult innerIndex(Index index) throws IOException {
700693 update (index .uid (), index .docs (), indexWriter );
701694 }
702695 indexResult = new IndexResult (updatedVersion , seqNo , deleted );
696+ location = index .origin () != Operation .Origin .LOCAL_TRANSLOG_RECOVERY
697+ ? translog .add (new Translog .Index (index , indexResult ))
698+ : null ;
703699 versionMap .putUnderLock (index .uid ().bytes (), new VersionValue (updatedVersion ));
704- final Translog .Index operation = new Translog .Index (index , indexResult );
705- location = index .origin () != Operation .Origin .LOCAL_TRANSLOG_RECOVERY ? translog .add (operation ) : null ;
700+ indexResult .setTranslogLocation (location );
706701 }
707- indexResult .setTranslogLocation (location );
708702 indexResult .setTook (System .nanoTime () - index .startTime ());
709703 indexResult .freeze ();
710704 return indexResult ;
@@ -808,26 +802,20 @@ private DeleteResult innerDelete(Delete delete) throws IOException {
808802 final DeleteResult deleteResult ;
809803 if (result .isPresent ()) {
810804 deleteResult = result .get ();
811- // norelease: this is not correct as this does not force an fsync, and we need to handle failures including replication
812- if (deleteResult .hasFailure () || seqNo == SequenceNumbersService .UNASSIGNED_SEQ_NO ) {
813- location = null ;
814- } else {
815- final Translog .NoOp operation = new Translog .NoOp (seqNo , delete .primaryTerm (), "version conflict during recovery" );
816- location = delete .origin () != Operation .Origin .LOCAL_TRANSLOG_RECOVERY ? translog .add (operation ) : null ;
817- }
818805 } else {
819806 if (delete .origin () == Operation .Origin .PRIMARY ) {
820807 seqNo = seqNoService ().generateSeqNo ();
821808 }
822809 updatedVersion = delete .versionType ().updateVersion (currentVersion , expectedVersion );
823810 found = deleteIfFound (delete .uid (), currentVersion , deleted , versionValue );
824811 deleteResult = new DeleteResult (updatedVersion , seqNo , found );
812+ location = delete .origin () != Operation .Origin .LOCAL_TRANSLOG_RECOVERY
813+ ? translog .add (new Translog .Delete (delete , deleteResult ))
814+ : null ;
825815 versionMap .putUnderLock (delete .uid ().bytes (),
826816 new DeleteVersionValue (updatedVersion , engineConfig .getThreadPool ().estimatedTimeInMillis ()));
827- final Translog .Delete operation = new Translog .Delete (delete , deleteResult );
828- location = delete .origin () != Operation .Origin .LOCAL_TRANSLOG_RECOVERY ? translog .add (operation ) : null ;
817+ deleteResult .setTranslogLocation (location );
829818 }
830- deleteResult .setTranslogLocation (location );
831819 deleteResult .setTook (System .nanoTime () - delete .startTime ());
832820 deleteResult .freeze ();
833821 return deleteResult ;
0 commit comments