Package com.linkedin.venice.meta
Class AsyncStoreChangeNotifier
java.lang.Object
com.linkedin.venice.meta.AsyncStoreChangeNotifier
- All Implemented Interfaces:
StoreDataChangedListener,AutoCloseable
@ThreadSafe
public class AsyncStoreChangeNotifier
extends Object
implements StoreDataChangedListener, AutoCloseable
Thread-safe notifier for store metadata changes in PubSub clients.
This notifier handles store data change events (creation, deletion, version changes) and propagates them to registered PubSub adapters by executing their registered tasks asynchronously.
Key Features:
- Event-specific tasks: Adapters register different tasks for different event types
- Rich context: Tasks receive full Store objects and version numbers
- Async execution: Tasks run in a thread pool to avoid blocking
- Failure isolation: Exceptions in one task don't affect others
- Change detection: Tracks version sets and current version for precise change detection
Usage Example:
AsyncStoreChangeNotifier notifier = new AsyncStoreChangeNotifier(
VeniceComponent.SERVER,
logContext,
4 // thread pool size
);
StoreChangeTasks tasks = StoreChangeTasks.builder()
.onVersionAdded((store, version) -> handleNewVersion(store, version))
.onCurrentVersionChanged((store, newVersion, oldVersion) ->
handleCurrentVersionChange(store, newVersion, oldVersion))
.build();
String taskId = notifier.registerTasks("MyAdapter", tasks);
// Later, when closing
notifier.unregisterTasks(taskId);
notifier.close();
Thread Safety: All public methods are thread-safe and can be called concurrently.
-
Constructor Summary
ConstructorsConstructorDescriptionAsyncStoreChangeNotifier(VeniceComponent veniceComponent, LogContext logContext, int threadPoolSize) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()intReturns the number of currently registered task sets.voidhandleStoreChanged(Store store) voidhandleStoreCreated(Store store) Do NOT try to acquire the lock of store repository again in the implementation, otherwise a dead lock issue will happen.voidhandleStoreDeleted(Store store) registerTasks(String clientId, StoreChangeTasks tasks) Registers tasks for store change events with a client-provided ID prefix.booleanunregisterTasks(String taskId) Unregisters previously registered tasks.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.linkedin.venice.meta.StoreDataChangedListener
handleStoreDeleted
-
Constructor Details
-
AsyncStoreChangeNotifier
public AsyncStoreChangeNotifier(VeniceComponent veniceComponent, LogContext logContext, int threadPoolSize)
-
-
Method Details
-
registerTasks
Registers tasks for store change events with a client-provided ID prefix.The notifier appends a unique suffix to ensure uniqueness. Callers should retain the returned task ID for later unregistration.
- Parameters:
clientId- client-provided ID prefix (e.g., adapter class name)tasks- the tasks to execute on store events- Returns:
- unique task ID in format "{clientId}-{uniqueSuffix}" for later unregistration
- Throws:
IllegalArgumentException- if clientId is null/empty or tasks is nullIllegalStateException- if notifier has been closed
-
unregisterTasks
Unregisters previously registered tasks.- Parameters:
taskId- the unique task ID returned fromregisterTasks(java.lang.String, com.linkedin.venice.meta.StoreChangeTasks)- Returns:
- true if tasks were found and removed, false otherwise
-
getRegisteredTaskCount
public int getRegisteredTaskCount()Returns the number of currently registered task sets. -
handleStoreCreated
Description copied from interface:StoreDataChangedListenerDo NOT try to acquire the lock of store repository again in the implementation, otherwise a dead lock issue will happen.- Specified by:
handleStoreCreatedin interfaceStoreDataChangedListener
-
handleStoreDeleted
- Specified by:
handleStoreDeletedin interfaceStoreDataChangedListener
-
handleStoreChanged
- Specified by:
handleStoreChangedin interfaceStoreDataChangedListener
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-