Class LocalityUtil

java.lang.Object
com.apple.foundationdb.LocalityUtil

public class LocalityUtil extends Object
The FoundationDB API comes with a set of functions for discovering the storage locations of keys within your cluster. This information can be useful for advanced users who wish to take into account the location of keys in the design of applications or processes.
  • Method Details

    • getBoundaryKeys

      public static CloseableAsyncIterator<byte[]> getBoundaryKeys(Database db, byte[] begin, byte[] end)
      Returns a CloseableAsyncIterator of keys k such that begin <= k < end and k is located at the start of a contiguous range stored on a single server.

      This method is not transactional. The returned boundaries are an estimate and may not represent the exact boundary locations at any database version.
      Parameters:
      db - the database to query
      begin - the inclusive start of the range
      end - the exclusive end of the range
      Returns:
      an sequence of keys denoting the start of single-server ranges
    • getBoundaryKeys

      public static CloseableAsyncIterator<byte[]> getBoundaryKeys(Transaction tr, byte[] begin, byte[] end)
      Returns a CloseableAsyncIterator of keys k such that begin <= k < end and k is located at the start of a contiguous range stored on a single server.

      This method is not transactional. The returned boundaries are an estimate and may not represent the exact boundary locations at any database version. The passed Transaction is not used for reads directly, instead it is used to get access to associated Database. As a result, options (such as retry limit) set on the passed Transaction will not be applied. If, however, the passed Transaction has already gotten a read version there is some latency advantage to using this form of the method. Also, if the database is unavailable prior to the function call, any timeout set on the passed Transaction will still trigger.
      Parameters:
      tr - the transaction on which to base the query
      begin - the inclusive start of the range
      end - the exclusive end of the range
      Returns:
      an sequence of keys denoting the start of single-server ranges
    • getAddressesForKey

      public static CompletableFuture<String[]> getAddressesForKey(Transaction tr, byte[] key)
      Returns a list of public network addresses as strings, one for each of the storage servers responsible for storing key and its associated value. The storage server network ports are not included to the list unless tr.options().setIncludePortInAddress() has been called. If locality information is not available, the returned future will carry a FDBException locality_information_unavailable.
      Parameters:
      tr - the transaction in which to gather location information
      key - the key for which to gather location information
      Returns:
      a list of addresses in string form