Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface LeaseManager

Package version

interface

LeaseManager If you wish to have EventProcessorHost store leases somewhere other than Azure Storage, you can write your own lease manager using this interface.

The Azure Storage managers use the same storage for both lease and checkpoints, so both interfaces are implemented by the same class. You are free to do the same thing if you have a unified store for both types of data.

This interface does not specify initialization methods because we have no way of knowing what information your implementation will require.

Hierarchy

  • LeaseManager

Index

Properties

leaseDuration

leaseDuration: number
property

{number} leaseDuration Duration of a lease in seconds before it expires unless renewed.

leaseRenewInterval

leaseRenewInterval: number
property

{number} leaseRenewInterval The sleep interval in seconds between scans.

Allows a lease manager implementation to specify to PartitionManager how often it should scan leases and renew them. In order to redistribute leases in a timely fashion after a host ceases operating, we recommend a relatively short interval, such as ten seconds. Obviously it should be less than half of the lease length, to prevent accidental expiration.

Methods

acquireLease

  • Acquire the lease on the desired partition for this EventProcessorHost.

    Note that it is legal to acquire a lease that is already owned by another host. Lease-stealing is how partitions are redistributed when additional hosts are started.

    The existing Azure Storage implementation can experience races between two host instances attempting to acquire or steal the lease at the same time. To avoid situations where two host instances both believe that they own the lease, acquisition can fail without errors by returning false and should do so when there is any doubt -- the worst that can happen is that no host instance owns the lease for a short time. This is qualitatively different from, for example, the underlying store throwing an access exception, which is an error.

    Parameters

    • lease: CompleteLease

      Lease info for the desired partition as previously obtained from getLease().

    Returns Promise<boolean>

    Promise true if acquired successfully; false otherwise.

createAllLeasesIfNotExists

  • createAllLeasesIfNotExists(partitionIds: string[]): Promise<void>
  • Create in the store the lease info for the given partition, if it does not exist. Do nothing if it does exist in the store already.

    Parameters

    • partitionIds: string[]

      ids of partitions to create lease info for

    Returns Promise<void>

    Promise undefined on success, rejects on error.

createLeaseStoreIfNotExists

  • createLeaseStoreIfNotExists(): Promise<void>
  • Create the lease store if it doesn't exist. Do nothing if it does exist.

    Returns Promise<void>

    Promise resolves with undefined; rejects with an Error.

deleteLease

  • Delete the lease info for the given partition from the store. If there is no stored lease for the given partition, that is treated as success.

    Parameters

    • lease: CompleteLease

      Lease info for the desired partition as previously obtained from getLease().

    Returns Promise<void>

    Promise resolves with undefined; rejects with an Error.

deleteLeaseStore

  • deleteLeaseStore(): Promise<void>
  • Delete lease store.

    Returns Promise<void>

    Promise resolves with undefined; rejects with an Error.

getAllLeases

  • Returns lightweight BaseLease for all leases, which includes name of owning host and whether lease is expired. An implementation is free to return CompleteLease or its own class derived from CompleteLease, but it is important that getAllLeases run as fast as possible. If it is faster to obtain only the information required for a BaseLease, we heavily recommend doing that.

    Returns Promise<BaseLease[]>

    Promise<BaseLease[]>

getLease

  • getLease(partitionId: string): Promise<CompleteLease | undefined>
  • Gets the lease info for the specified partition. Can return undefined if no lease has been created in the store for the specified partition.

    Parameters

    • partitionId: string

      Partition id to get the lease for.

    Returns Promise<CompleteLease | undefined>

    Promise<Lease | undefined>

leaseStoreExists

  • leaseStoreExists(): Promise<boolean>
  • Does the lease store exist?

    Returns Promise<boolean>

    Promise true if it exists, false if it does not exist.

releaseLease

  • Give up a lease currently held by this host.

    If the lease has been stolen, or expired, releasing it is unnecessary, and will fail if attempted.

    Parameters

    • lease: CompleteLease

      Lease info for the desired partition as previously obtained from getLease().

    Returns Promise<void>

    Promise resolves with undefined; rejects with an Error.

renewLease

  • Renew a lease currently held by this host.

    If the lease has been taken by another host instance (either stolen or after expiration) or explicitly released, renewLease must return false. With the Azure Storage-based implementation, it IS possible to renew an expired lease that has not been taken by another host, so your implementation can allow that or not, whichever is convenient. If it does not, renewLease should return false.

    Parameters

    Returns Promise<boolean>

    Promise true if renewed successfully; false otherwise.

updateLease

  • Update the store with the information in the provided lease.

    It is necessary to currently hold a lease in order to update it. If the lease has been stolen, or expired, or released, it cannot be updated. Lease manager implementations should renew the lease before performing the update to avoid lease expiration during the process.

    Parameters

    Returns Promise<boolean>

    Promise true if updated successfully; false otherwise.

Generated using TypeDoc