java.lang.Object
org.apache.hadoop.hdfs.server.federation.router.security.token.DistributedSQLCounter

public class DistributedSQLCounter extends Object
Distributed counter that relies on a SQL database to synchronize between multiple clients. This expects a table with a single int field to exist in the database. One record must exist on the table at all times, representing the last used value reserved by a client.
  • Constructor Details

  • Method Details

    • selectCounterValue

      public int selectCounterValue() throws SQLException
      Obtains the value of the counter.
      Returns:
      counter value.
      Throws:
      SQLException - if querying the database fails.
    • updateCounterValue

      public void updateCounterValue(int value) throws SQLException
      Sets the counter to the given value.
      Parameters:
      value - Value to assign to counter.
      Throws:
      SQLException - if querying the database fails.
    • updateCounterValue

      public void updateCounterValue(int value, Connection connection) throws SQLException
      Sets the counter to the given value.
      Parameters:
      value - Value to assign to counter.
      connection - Connection to database hosting the counter table.
      Throws:
      SQLException - if querying the database fails.
    • incrementCounterValue

      public int incrementCounterValue(int amount) throws SQLException
      Increments the counter by the given amount and returns the previous counter value.
      Parameters:
      amount - Amount to increase the counter.
      Returns:
      Previous counter value.
      Throws:
      SQLException - if querying the database fails.