Skip to content

Commit

Permalink
Changing logic to Just trigger refresh, and leave trimtranslog on Aft…
Browse files Browse the repository at this point in the history
…erWriteAction, which trims unreferenced translog readers after every write

Signed-off-by: Shubh Sahu <[email protected]>
  • Loading branch information
Shubh Sahu committed Apr 3, 2024
1 parent f24757d commit 5f4ca3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
INDEX_DOC_ID_FUZZY_SET_FALSE_POSITIVE_PROBABILITY_SETTING,
this::setDocIdFuzzySetFalsePositiveProbability
);
scopedSettings.addSettingsUpdateConsumer(INDEX_MAX_UNCOMMITTED_TRANSLOG_FILES,this::setMaxUncommittedTranslogFiles);
scopedSettings.addSettingsUpdateConsumer(INDEX_MAX_UNCOMMITTED_TRANSLOG_FILES, this::setMaxUncommittedTranslogFiles);
}

private void setMaxUncommittedTranslogFiles(int maxUncommittedTranslogFiles) {
Expand Down
18 changes: 6 additions & 12 deletions server/src/main/java/org/opensearch/index/shard/IndexShard.java
Original file line number Diff line number Diff line change
Expand Up @@ -4489,7 +4489,7 @@ public Durability getTranslogDurability() {
* threshold count determined by {@code index.translog.max_uncommitted_files_threshold}
* @return {@code true} if the shard should be Refreshed
*/
boolean shouldRefreshShard(){
boolean shouldRefreshShard() {
final Engine engine = getEngineOrNull();
if (engine != null) {
try {
Expand All @@ -4503,17 +4503,11 @@ boolean shouldRefreshShard(){

private final AtomicBoolean isRefreshRunning = new AtomicBoolean();

/**
* Will Call a blocking Refresh and then Trim the Unreferenced Translog files
*/
private void refreshAndTrimTranslogfiles(String source) throws IOException {
refresh(source);
getEngine().translogManager().trimUnreferencedTranslogFiles();
}

/**
* Schedules a flush or translog generation roll if needed but will not schedule more than one concurrently. The operation will be
* executed asynchronously on the flush thread pool.
* Also Schedules a refresh if Number of Translog files breaches the threshold count determined by
* {@code index.translog.max_uncommitted_files_threshold}
*/
public void afterWriteOperation() {
if (shouldPeriodicallyFlush() || shouldRollTranslogGeneration()) {
Expand Down Expand Up @@ -4579,15 +4573,15 @@ public void onAfter() {

if (shouldRefreshShard()) {
logger.info("submitting async Refresh request");
final AbstractRunnable refreshAndTrimTranslog = new AbstractRunnable() {
final AbstractRunnable _refresh = new AbstractRunnable() {
@Override
public void onFailure(Exception e) {
logger.warn("forced refresh failed after number of uncommited translog files breached limit", e);
}

@Override
protected void doRun() throws Exception {
refreshAndTrimTranslogfiles("Too many uncommited Translog files");
refresh("Too many uncommited Translog files");
}

@Override
Expand All @@ -4600,7 +4594,7 @@ public void onAfter() {
isRefreshRunning.compareAndSet(true, false);
}
};
threadPool.executor(ThreadPool.Names.REFRESH).execute(refreshAndTrimTranslog);
threadPool.executor(ThreadPool.Names.REFRESH).execute(_refresh);
} else {
isRefreshRunning.compareAndSet(true, false);
}
Expand Down

0 comments on commit 5f4ca3a

Please sign in to comment.