Description
There appears to be a bug in the logic that computes the segment count of a shard snapshot in some background merge scenarios.
The segment count is taken from the index commit that we are snapshotting via a call to org.apache.lucene.index.IndexCommit#getSegmentCount
. This is correct for all snapshots except for those that use the sequence number based shortcut introduced in #52182 that will prevent an updated set of files from getting uploaded when there already is a shard copy at the same sequence number that is in the current index commit.
This means that if a snapshot is taken once before a background merge and once after without any indexing into the shard, then the segment count stored for the second snapshot will be wrong if segment counts for the shard changed. We can fix this by taking the segment count from the files list instead in this case.