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 Details

    • AsyncStoreChangeNotifier

      public AsyncStoreChangeNotifier(VeniceComponent veniceComponent, LogContext logContext, int threadPoolSize)
  • Method Details

    • registerTasks

      public String registerTasks(String clientId, StoreChangeTasks tasks)
      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 null
      IllegalStateException - if notifier has been closed
    • unregisterTasks

      public boolean unregisterTasks(String taskId)
      Unregisters previously registered tasks.
      Parameters:
      taskId - the unique task ID returned from registerTasks(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

      public void handleStoreCreated(Store store)
      Description copied from interface: StoreDataChangedListener
      Do NOT try to acquire the lock of store repository again in the implementation, otherwise a dead lock issue will happen.
      Specified by:
      handleStoreCreated in interface StoreDataChangedListener
    • handleStoreDeleted

      public void handleStoreDeleted(Store store)
      Specified by:
      handleStoreDeleted in interface StoreDataChangedListener
    • handleStoreChanged

      public void handleStoreChanged(Store store)
      Specified by:
      handleStoreChanged in interface StoreDataChangedListener
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable