-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for translog fetch at the leader(remote) cluster
and enable translog pruning during replication setup
- Loading branch information
1 parent
bcd2ae1
commit 145ec1c
Showing
7 changed files
with
211 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/kotlin/com/amazon/elasticsearch/replication/seqno/RemoteClusterTranslogService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.amazon.elasticsearch.replication.seqno | ||
|
||
import org.apache.logging.log4j.LogManager | ||
import org.elasticsearch.ResourceNotFoundException | ||
import org.elasticsearch.common.component.AbstractLifecycleComponent | ||
import org.elasticsearch.common.inject.Singleton | ||
import org.elasticsearch.core.internal.io.IOUtils | ||
import org.elasticsearch.index.engine.Engine | ||
import org.elasticsearch.index.shard.IndexShard | ||
import org.elasticsearch.index.translog.Translog | ||
import java.io.Closeable | ||
|
||
@Singleton | ||
class RemoteClusterTranslogService : AbstractLifecycleComponent(){ | ||
companion object { | ||
private val log = LogManager.getLogger(RemoteClusterTranslogService::class.java) | ||
private const val SOURCE_NAME = "os_plugin_replication" | ||
} | ||
|
||
override fun doStart() { | ||
} | ||
|
||
override fun doStop() { | ||
} | ||
|
||
override fun doClose() { | ||
} | ||
|
||
public fun getHistoryOfOperations(indexShard: IndexShard, startSeqNo: Long, toSeqNo: Long): List<Translog.Operation> { | ||
if(!indexShard.hasCompleteHistoryOperations(SOURCE_NAME, Engine.HistorySource.TRANSLOG, startSeqNo)) { | ||
log.debug("Doesn't have history of operations starting from $startSeqNo") | ||
throw ResourceNotFoundException("$indexShard doesn't contain ops starting from $startSeqNo " + | ||
"with source ${Engine.HistorySource.TRANSLOG.name}") | ||
} | ||
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())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.