Package org.elasticsearch.index.shard
Class RefreshListeners
java.lang.Object
org.elasticsearch.index.shard.RefreshListeners
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.apache.lucene.search.ReferenceManager.RefreshListener
public final class RefreshListeners
extends Object
implements org.apache.lucene.search.ReferenceManager.RefreshListener, Closeable
Allows for the registration of listeners that are called when a change becomes visible for search. This functionality is exposed from
IndexShard
but kept here so it can be tested without standing up the entire thing.
When Closeable.close()
d it will no longer accept listeners and flush any existing listeners.-
Constructor Summary
ConstructorDescriptionRefreshListeners
(IntSupplier getMaxRefreshListeners, Runnable forceRefresh, org.apache.logging.log4j.Logger logger, ThreadContext threadContext, MeanMetric refreshMetric) -
Method Summary
Modifier and TypeMethodDescriptionboolean
addOrNotify
(long checkpoint, ActionListener<Void> listener) Add a listener for refreshes, calling it immediately if the location is already visible.boolean
addOrNotify
(Translog.Location location, Consumer<Boolean> listener) Add a listener for refreshes, calling it immediately if the location is already visible.void
afterRefresh
(boolean didRefresh) void
void
close()
Force-refreshes newly added listeners and forces a refresh if there are currently listeners registered.int
The total number of pending listeners.boolean
Returns true if there are pending listeners.void
setCurrentProcessedCheckpointSupplier
(LongSupplier processedCheckpointSupplier) Setup the engine used to find the last processed sequence number checkpoint.void
setCurrentRefreshLocationSupplier
(Supplier<Translog.Location> currentRefreshLocationSupplier) Setup the translog used to find the last refreshed location.void
setMaxIssuedSeqNoSupplier
(LongSupplier maxIssuedSeqNoSupplier) Setup the engine used to find the max issued seqNo.
-
Constructor Details
-
RefreshListeners
public RefreshListeners(IntSupplier getMaxRefreshListeners, Runnable forceRefresh, org.apache.logging.log4j.Logger logger, ThreadContext threadContext, MeanMetric refreshMetric)
-
-
Method Details
-
forceRefreshes
Force-refreshes newly added listeners and forces a refresh if there are currently listeners registered. SeerefreshForcers
. -
addOrNotify
Add a listener for refreshes, calling it immediately if the location is already visible. If this runs out of listener slots then it forces a refresh and calls the listener immediately as well.- Parameters:
location
- the location to listen forlistener
- for the refresh. Called with true if registering the listener ran it out of slots and forced a refresh. Called with false otherwise.- Returns:
- did we call the listener (true) or register the listener to call later (false)?
-
addOrNotify
Add a listener for refreshes, calling it immediately if the location is already visible. If this runs out of listener slots then it fails the listener immediately. The checkpoint cannot be greater than the processed local checkpoint. This method does not respect the forceRefreshes state. It will NEVER force a refresh on the calling thread. Instead, it will simply add listeners or rejected them if too many listeners are already waiting.- Parameters:
checkpoint
- the seqNo checkpoint to listen forlistener
- for the refresh.- Returns:
- did we call the listener (true) or register the listener to call later (false)?
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
refreshNeeded
public boolean refreshNeeded()Returns true if there are pending listeners. -
pendingCount
public int pendingCount()The total number of pending listeners. -
setCurrentRefreshLocationSupplier
public void setCurrentRefreshLocationSupplier(Supplier<Translog.Location> currentRefreshLocationSupplier) Setup the translog used to find the last refreshed location. -
setCurrentProcessedCheckpointSupplier
Setup the engine used to find the last processed sequence number checkpoint. -
setMaxIssuedSeqNoSupplier
Setup the engine used to find the max issued seqNo. -
beforeRefresh
- Specified by:
beforeRefresh
in interfaceorg.apache.lucene.search.ReferenceManager.RefreshListener
- Throws:
IOException
-
afterRefresh
- Specified by:
afterRefresh
in interfaceorg.apache.lucene.search.ReferenceManager.RefreshListener
- Throws:
IOException
-