-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Fix expiration time in async search response #55435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
7adb0b0
df22f66
47f3544
bf01fc0
812cf0b
09afaca
c9ff64f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
import org.elasticsearch.cluster.ClusterStateListener; | ||
import org.elasticsearch.cluster.routing.IndexRoutingTable; | ||
import org.elasticsearch.common.lease.Releasable; | ||
import org.elasticsearch.common.settings.Setting; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; | ||
import org.elasticsearch.gateway.GatewayService; | ||
|
@@ -26,13 +28,17 @@ | |
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static org.elasticsearch.xpack.search.AsyncSearchIndexService.EXPIRATION_TIME_FIELD; | ||
import static org.elasticsearch.xpack.search.AsyncSearchIndexService.INDEX; | ||
|
||
/** | ||
* A service that runs a periodic cleanup over the async-search index. | ||
*/ | ||
class AsyncSearchMaintenanceService implements Releasable, ClusterStateListener { | ||
private static final Logger logger = LogManager.getLogger(AsyncSearchMaintenanceService.class); | ||
|
||
public static final Setting<TimeValue> ASYNC_SEARCH_CLEANUP_INTERVAL_SETTING = | ||
Setting.timeSetting("async_search.index_cleanup_interval", TimeValue.timeValueHours(1), Setting.Property.NodeScope); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we plan on using this new setting only in our tests? Or can it be useful for users too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe for debug but I don't think it's useful for users, only for tests at the moment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no way to somehow make this "private" or for use only in our tests? I worry mostly about naming, and the fact that users may end up using it although we would not want them to. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default value is quite large (1h) so maybe there's some value to change it. I am not sure, I can make it private but that would work only in fantasy integration tests (single vm) so this will come back. I was expecting that the lack of documentation would make this setting an expert thing that users would never heard from ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea I see, can you add a comment that this is intentionally undocumented? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I pushed 09afaca |
||
|
||
private final String localNodeId; | ||
private final ThreadPool threadPool; | ||
private final AsyncSearchIndexService indexService; | ||
|
@@ -43,13 +49,13 @@ class AsyncSearchMaintenanceService implements Releasable, ClusterStateListener | |
private volatile Scheduler.Cancellable cancellable; | ||
|
||
AsyncSearchMaintenanceService(String localNodeId, | ||
Settings nodeSettings, | ||
ThreadPool threadPool, | ||
AsyncSearchIndexService indexService, | ||
TimeValue delay) { | ||
AsyncSearchIndexService indexService) { | ||
this.localNodeId = localNodeId; | ||
this.threadPool = threadPool; | ||
this.indexService = indexService; | ||
this.delay = delay; | ||
this.delay = ASYNC_SEARCH_CLEANUP_INTERVAL_SETTING.get(nodeSettings); | ||
} | ||
|
||
@Override | ||
|
@@ -62,31 +68,29 @@ public void clusterChanged(ClusterChangedEvent event) { | |
tryStartCleanup(state); | ||
} | ||
|
||
void tryStartCleanup(ClusterState state) { | ||
synchronized void tryStartCleanup(ClusterState state) { | ||
jimczi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (isClosed.get()) { | ||
return; | ||
} | ||
IndexRoutingTable indexRouting = state.routingTable().index(AsyncSearchIndexService.INDEX); | ||
if (indexRouting == null) { | ||
if (isCleanupRunning.compareAndSet(true, false)) { | ||
close(); | ||
} | ||
stop(); | ||
return; | ||
} | ||
String primaryNodeId = indexRouting.shard(0).primaryShard().currentNodeId(); | ||
if (localNodeId.equals(primaryNodeId)) { | ||
if (isCleanupRunning.compareAndSet(false, true)) { | ||
executeNextCleanup(); | ||
} | ||
} else if (isCleanupRunning.compareAndSet(true, false)) { | ||
close(); | ||
} else { | ||
stop(); | ||
} | ||
} | ||
|
||
synchronized void executeNextCleanup() { | ||
if (isClosed.get() == false && isCleanupRunning.get()) { | ||
long nowInMillis = System.currentTimeMillis(); | ||
DeleteByQueryRequest toDelete = new DeleteByQueryRequest() | ||
DeleteByQueryRequest toDelete = new DeleteByQueryRequest(INDEX) | ||
.setQuery(QueryBuilders.rangeQuery(EXPIRATION_TIME_FIELD).lte(nowInMillis)); | ||
indexService.getClient() | ||
.execute(DeleteByQueryAction.INSTANCE, toDelete, ActionListener.wrap(() -> scheduleNextCleanup())); | ||
|
@@ -107,11 +111,17 @@ synchronized void scheduleNextCleanup() { | |
} | ||
} | ||
|
||
synchronized void stop() { | ||
if (isCleanupRunning.compareAndSet(true, false)) { | ||
if (cancellable != null && cancellable.isCancelled() == false) { | ||
cancellable.cancel(); | ||
} | ||
} | ||
} | ||
jimczi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Override | ||
public void close() { | ||
if (cancellable != null && cancellable.isCancelled() == false) { | ||
cancellable.cancel(); | ||
} | ||
stop(); | ||
isClosed.compareAndSet(false, true); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.