Skip to content

Commit 08c4051

Browse files
authored
Add origin for post write refresh (elastic#95506)
Which sends unpromotable refresh actions internally Relates ES-5884
1 parent 66166b5 commit 08c4051

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

server/src/main/java/org/elasticsearch/action/support/replication/PostWriteRefresh.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.action.admin.indices.refresh.TransportUnpromotableShardRefreshAction;
1616
import org.elasticsearch.action.admin.indices.refresh.UnpromotableShardRefreshRequest;
1717
import org.elasticsearch.action.support.WriteRequest;
18+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1819
import org.elasticsearch.core.Nullable;
1920
import org.elasticsearch.core.TimeValue;
2021
import org.elasticsearch.index.engine.Engine;
@@ -26,6 +27,7 @@
2627

2728
public class PostWriteRefresh {
2829

30+
public static final String POST_WRITE_REFRESH_ORIGIN = "post_write_refresh";
2931
public static final String FORCED_REFRESH_AFTER_INDEX = "refresh_flag_index";
3032
private final TransportService transportService;
3133

@@ -119,7 +121,13 @@ private void refreshUnpromotables(
119121
engineOrNull.addFlushListener(location, ActionListener.wrap(new ActionListener<>() {
120122
@Override
121123
public void onResponse(Long generation) {
122-
sendUnpromotableRequests(indexShard, generation, forced, listener, postWriteRefreshTimeout);
124+
try (
125+
ThreadContext.StoredContext ignore = transportService.getThreadPool()
126+
.getThreadContext()
127+
.stashWithOrigin(POST_WRITE_REFRESH_ORIGIN)
128+
) {
129+
sendUnpromotableRequests(indexShard, generation, forced, listener, postWriteRefreshTimeout);
130+
}
123131
}
124132

125133
@Override

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/AuthorizationUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
import org.elasticsearch.xpack.core.security.support.Automatons;
1717
import org.elasticsearch.xpack.core.security.user.AsyncSearchUser;
1818
import org.elasticsearch.xpack.core.security.user.SecurityProfileUser;
19+
import org.elasticsearch.xpack.core.security.user.StorageInternalUser;
1920
import org.elasticsearch.xpack.core.security.user.XPackSecurityUser;
2021
import org.elasticsearch.xpack.core.security.user.XPackUser;
2122

2223
import java.util.function.Consumer;
2324
import java.util.function.Predicate;
2425

2526
import static org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskAction.TASKS_ORIGIN;
27+
import static org.elasticsearch.action.support.replication.PostWriteRefresh.POST_WRITE_REFRESH_ORIGIN;
2628
import static org.elasticsearch.cluster.metadata.DataLifecycle.DLM_ORIGIN;
2729
import static org.elasticsearch.ingest.IngestService.INGEST_ORIGIN;
2830
import static org.elasticsearch.persistent.PersistentTasksService.PERSISTENT_TASK_ORIGIN;
@@ -125,6 +127,9 @@ public static void switchUserBasedOnActionOriginAndExecute(
125127
case SECURITY_PROFILE_ORIGIN:
126128
securityContext.executeAsInternalUser(SecurityProfileUser.INSTANCE, version, consumer);
127129
break;
130+
case POST_WRITE_REFRESH_ORIGIN:
131+
securityContext.executeAsInternalUser(StorageInternalUser.INSTANCE, version, consumer);
132+
break;
128133
case WATCHER_ORIGIN:
129134
case ML_ORIGIN:
130135
case MONITORING_ORIGIN:

0 commit comments

Comments
 (0)