code: func (w *IndexWriter) publishFlushedSegment(newSegment *SegmentCommitInfo,
  	packet *FrozenBufferedUpdates, globalPacket *FrozenBufferedUpdates) (err error) {
  	defer func() {
  		atomic.AddInt32(&w.flushCount, 1)
  		err = mergeError(err, w.doAfterFlush())
  	}()
  
  	// Lock order IW -> BDS
  	w.Lock()
  	defer w.Unlock()
  	w.ClosingControl.ensureOpen(false)
  	w.bufferedUpdatesStreamLock.Lock()
  	defer w.bufferedUpdatesStreamLock.Unlock()
  
  	if w.infoStream.IsEnabled("IW") {
  		w.infoStream.Message("IW", "publishFlushedSegment")
  	}
  
  	if globalPacket != nil && globalPacket.any() {
  		w.bufferedUpdatesStream.push(globalPacket)
  	}
  	// Publishing the segment must be synched on IW -> BDS to make sure
  	// that no merge prunes away the seg. private delete packet
  	var nextGen int64
  	if packet != nil && packet.any() {
  		nextGen = w.bufferedUpdatesStream.push(packet)
  	} else {
  		// Since we don't have a delete packet to apply we can get a new
  		// generation right away
  		nextGen = w.bufferedUpdatesStream.nextGen
  	}
  	if w.infoStream.IsEnabled("IW") {
  		w.infoStream.Message("IW", "publish sets newSegment delGen=%v seg=%v", nextGen, w.readerPool.segmentToString(newSegment))
  	}
  	newSegment.SetBufferedUpdatesGen(nextGen)
  	w.segmentInfos.Segments = append(w.segmentInfos.Segments, newSegment)
  	return w._checkpoint()
  }
docs: /*
  Atomically adds the segment private delete packet and publishes the
  flushed segments SegmentInfo to the index writer.
  */