Class PluginHandle

java.lang.Object
org.apache.drill.exec.store.PluginHandle

public class PluginHandle extends Object
Represents a storage plugin, defined by a (name, config) pair. The config implies a connector definition, including a way to create the plugin instance (StoragePlugin. Storage plugins are created lazily to avoid long Drillbit start times. Plugin creation is synchronized as is closing.

A handle has a type used to determine which operations are allowed on the handle. For example, inrinsic (system) plugins cannot be deleted or disabled.

Caveats

Note that race conditions are still possible:
  • User 1 submits a query that refers to plugin p. The registry creates an instance of plugin p and returns it. The planner proceeds to use it.
  • User 2 disables p, causing its entry to be updated in persistent storage (but not yet in this entry)
  • User 3 submits a query that refers to plugin p. The registry notices that the plugin is now disabled, removes it from the plugin list and closes the plugin.
  • User 1 suffers a failure when the planner references the now-closed plugin p.
This issue has existed for some time and cannot be fixed here. The right solution is to introduce a reference count: each query which uses the plugin should hold a reference count until the completion of the plan or fragment. If we implement such a reference count, this is the place to maintain the count, and to close the plugin when the count goes to zero.
  • Constructor Details

  • Method Details

    • name

      public String name()
    • config

      public StoragePluginConfig config()
    • isStored

      public boolean isStored()
    • isIntrinsic

      public boolean isIntrinsic()
    • plugin

      public StoragePlugin plugin()
      Retrieve the storage plugin instance, creating it if needed. Creation can take time if the plugin creates a connection to another system, especially if that system suffers timeouts.
      Returns:
      the initialized storage plugin
      Throws:
      UserException - if the storage plugin creation failed due to class errors (unlikely) or external system errors (more likely)
    • hasInstance

      public boolean hasInstance()
    • close

      public void close()
      Close the plugin. Can occur when the handle is evicted from the loading cache where we must not throw an exception. Also called on shutdown.
    • transfer

      public PluginHandle transfer(org.apache.drill.exec.store.PluginHandle.PluginType type)
      Atomically transfer the plugin instance, if any, to a new handle of the given type. Avoids race conditions when transferring a plugin from/to ephemeral storage and the plugin cache, since those two caches are not synchronized as a whole. Ensures that only one of the threads in a race condition will transfer the actual plugin instance.

      By definition, a plugin becomes disabled if it moves to ephemeral, enabled if it moves from ephemeral into stored status.

    • toString

      public String toString()
      Overrides:
      toString in class Object