public fun getHistoryOfOperations()

in src/main/kotlin/org/opensearch/replication/seqno/RemoteClusterTranslogService.kt [38:68]


    public fun getHistoryOfOperations(indexShard: IndexShard, startSeqNo: Long, toSeqNo: Long): List<Translog.Operation> {
        log.trace("Fetching translog snapshot for $indexShard - from $startSeqNo to $toSeqNo")
        val snapshot = indexShard.getHistoryOperations(SOURCE_NAME, Engine.HistorySource.TRANSLOG, startSeqNo, toSeqNo)

        // Total ops to be fetched (both toSeqNo and startSeqNo are inclusive)
        val opsSize = toSeqNo - startSeqNo + 1
        val ops = ArrayList<Translog.Operation>(opsSize.toInt())

        // Filter and sort specific ops from the obtained history
        var filteredOpsFromTranslog = 0
        snapshot.use {
            var op  = snapshot.next()
            while(op != null) {
                if(op.seqNo() in startSeqNo..toSeqNo) {
                    ops.add(op)
                    filteredOpsFromTranslog++
                }
                op = snapshot.next()
            }
        }
        assert(filteredOpsFromTranslog == opsSize.toInt()) {"Missing operations while fetching from translog"}

        val sortedOps = ArrayList<Translog.Operation>(opsSize.toInt())
        sortedOps.addAll(ops)
        for(ele in ops) {
            sortedOps[(ele.seqNo() - startSeqNo).toInt()] = ele
        }

        log.debug("Starting seqno after sorting ${sortedOps[0].seqNo()} and ending seqno ${sortedOps[ops.size-1].seqNo()}")
        return sortedOps.subList(0, ops.size.coerceAtMost((opsSize).toInt()))
    }