Class HubClusterId

java.lang.Object
com.iizix.server.hub.HubClusterId

public final class HubClusterId extends Object
The shared-DB identity of a hub, HUB-DESIGN.md section 2.3: one row of HUB.CLUSTER per hub holding a random UUID. The first eligible member to start on an empty HUB schema inserts it (ensure(String), called by the hub module after it created the tables); every member reads it from ITS OWN connection pool (read(String)) and reports the UUID at registration, so that two pools that return the same row are the same database - a measurement, not a configuration flag. A member whose database has no HUB schema, or no row, reports an empty db: a local-DB member, never in a transfer and never principal.
Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The qualified table: "HUB.CLUSTER".
    static final String
    The SQLState of a unique-key violation on Derby and PostgreSQL ("23505") and on MySQL ("23000"): the other writer committed first.
    static final String
    The SQLState of a unique-key violation on Derby and PostgreSQL ("23505") and on MySQL ("23000"): the other writer committed first.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    ensure(String hubName)
    Inserts the hub's row with a random UUID when there is none, on this server's own pool: the first eligible member wins the race, the other reads the winner's row.
    static String
    ensure(Connection conn, String hubName)
    Inserts the hub's row with a random UUID when there is none, on a connection that is committed or rolled back here.
    static String
    read(String hubName)
    Reads the hub's cluster UUID from this server's own connection pool.
    static String
    read(Connection conn, String hubName)
    Reads the hub's cluster UUID on a connection.
  • Field Details

    • TABLE

      public static final String TABLE
      The qualified table: "HUB.CLUSTER".
      See Also:
    • UNIQUE_VIOLATION

      public static final String UNIQUE_VIOLATION
      The SQLState of a unique-key violation on Derby and PostgreSQL ("23505") and on MySQL ("23000"): the other writer committed first.
      See Also:
    • UNIQUE_VIOLATION_MYSQL

      public static final String UNIQUE_VIOLATION_MYSQL
      The SQLState of a unique-key violation on Derby and PostgreSQL ("23505") and on MySQL ("23000"): the other writer committed first.
      See Also:
  • Method Details

    • read

      public static String read(String hubName)
      Reads the hub's cluster UUID from this server's own connection pool.
      Parameters:
      hubName - The hub's name, the key of the row.
      Returns:
      The UUID, or null when the database holds no HUB schema, no row, or cannot be reached (logged at FINE: a member without the hub module has no schema).
    • read

      public static String read(Connection conn, String hubName) throws SQLException
      Reads the hub's cluster UUID on a connection.
      Parameters:
      conn - The connection.
      hubName - The hub's name.
      Returns:
      The UUID, or null for no row.
      Throws:
      SQLException - For SQL errors, e.g. no HUB schema.
    • ensure

      public static String ensure(String hubName) throws SQLException
      Inserts the hub's row with a random UUID when there is none, on this server's own pool: the first eligible member wins the race, the other reads the winner's row.
      Parameters:
      hubName - The hub's name.
      Returns:
      The UUID in the database after the call.
      Throws:
      SQLException - For SQL errors.
    • ensure

      public static String ensure(Connection conn, String hubName) throws SQLException
      Inserts the hub's row with a random UUID when there is none, on a connection that is committed or rolled back here.
      Parameters:
      conn - The connection.
      hubName - The hub's name.
      Returns:
      The UUID in the database after the call.
      Throws:
      SQLException - For SQL errors.