/**
   * Store an end-point to host ID mapping. Each ID must be unique, and cannot be changed after the
   * fact.
   *
   * @param hostId
   * @param endpoint
   */
  public void updateHostId(UUID hostId, InetAddress endpoint) {
    assert hostId != null;
    assert endpoint != null;

    lock.writeLock().lock();
    try {
      InetAddress storedEp = endpointToHostIdMap.inverse().get(hostId);
      if (storedEp != null) {
        if (!storedEp.equals(endpoint) && (FailureDetector.instance.isAlive(storedEp))) {
          throw new RuntimeException(
              String.format(
                  "Host ID collision between active endpoint %s and %s (id=%s)",
                  storedEp, endpoint, hostId));
        }
      }

      UUID storedId = endpointToHostIdMap.get(endpoint);
      if ((storedId != null) && (!storedId.equals(hostId)))
        logger.warn("Changing {}'s host ID from {} to {}", endpoint, storedId, hostId);

      endpointToHostIdMap.forcePut(endpoint, hostId);
    } finally {
      lock.writeLock().unlock();
    }
  }
示例#2
0
 static {
   try {
     emptyVersion = UUID.nameUUIDFromBytes(MessageDigest.getInstance("MD5").digest());
   } catch (NoSuchAlgorithmException e) {
     throw new AssertionError();
   }
 }
示例#3
0
 final Set<UUID> getPlayers() {
   ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
   if (pool != null) {
     try (Jedis rsc = pool.getResource()) {
       List<String> keys = new ArrayList<>();
       for (String i : getServerIds()) {
         keys.add("proxy:" + i + ":usersOnline");
       }
       if (!keys.isEmpty()) {
         Set<String> users = rsc.sunion(keys.toArray(new String[keys.size()]));
         if (users != null && !users.isEmpty()) {
           for (String user : users) {
             try {
               setBuilder = setBuilder.add(UUID.fromString(user));
             } catch (IllegalArgumentException ignored) {
             }
           }
         }
       }
     } catch (JedisConnectionException e) {
       // Redis server has disappeared!
       getLogger()
           .log(
               Level.SEVERE,
               "Unable to get connection from pool - did your Redis server go away?",
               e);
       throw new RuntimeException("Unable to get all players online", e);
     }
   }
   return setBuilder.build();
 }
示例#4
0
 public Set<UUID> getPlayersOnProxy(String server) {
   checkArgument(getServerIds().contains(server), server + " is not a valid proxy ID");
   try (Jedis jedis = pool.getResource()) {
     Set<String> users = jedis.smembers("proxy:" + server + ":usersOnline");
     ImmutableSet.Builder<UUID> builder = ImmutableSet.builder();
     for (String user : users) {
       builder.add(UUID.fromString(user));
     }
     return builder.build();
   }
 }
示例#5
0
 final Set<UUID> getPlayersOnServer(@NonNull String server) {
   checkArgument(getProxy().getServers().containsKey(server), "server does not exist");
   Collection<String> asStrings =
       (Collection<String>)
           getServerPlayersScript.eval(
               ImmutableList.<String>of(), ImmutableList.<String>of(server));
   ImmutableSet.Builder<UUID> builder = ImmutableSet.builder();
   for (String s : asStrings) {
     builder.add(UUID.fromString(s));
   }
   return builder.build();
 }
示例#6
0
  /**
   * Read schema from system table and calculate MD5 digest of every row, resulting digest will be
   * converted into UUID which would act as content-based version of the schema.
   */
  public void updateVersion() {
    try {
      MessageDigest versionDigest = MessageDigest.getInstance("MD5");

      for (Row row : SystemTable.serializedSchema()) {
        if (invalidSchemaRow(row) || ignoredSchemaRow(row)) continue;

        row.cf.updateDigest(versionDigest);
      }

      version = UUID.nameUUIDFromBytes(versionDigest.digest());
      SystemTable.updateSchemaVersion(version);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }