for (Config.ConfigMember member : config.getMembersInHost(hostId)) { try { trace("[{}-{}] Initializing zookeeper node...", gondola.getHostId(), member.getMemberId()); String actionPath = actionPath(serviceName, member.getMemberId()); String statPath = statPath(serviceName, member.getMemberId()); ZookeeperStat stat; ZookeeperAction action; } catch (Exception e) { stat = new ZookeeperStat(); stat.memberId = member.getMemberId(); stat.shardId = member.getShardId(); client.create().creatingParentContainersIfNeeded() .forPath(statPath, objectMapper.writeValueAsBytes(stat)); } catch (Exception e) { action = new ZookeeperAction(); action.memberId = member.getMemberId(); client.create().creatingParentContainersIfNeeded() .forPath(actionPath, objectMapper.writeValueAsBytes(action)); currentStats.put(member.getMemberId(), stat); processAction(action); NodeCache node = new NodeCache(client, actionPath); } catch (Exception e) { logger.warn("[{}-{}] Unable to create member node, msg={}", gondola.getHostId(), member.getMemberId(), e.getMessage(), e);
ConfigMember cm = new ConfigMember(v.getString("clusterId"), h.getString("hostId"), h.getInt("memberId"));
if (masterId >= 0) { String shardId = gondola.getConfig().getMember(masterId).getShardId(); if (shardId.equals(gondola.getConfig().getMember(memberId).getShardId())) { throw new GondolaException(GondolaException.Code.SAME_SHARD, memberId, masterId, shardId);
String appUri = Utils.getAppUri(config, config.getMember(roleChangeEvent.leader.getMemberId()).getHostId()); updateShardRoutingEntries(roleChangeEvent.shard.getShardId(), appUri); if (roleChangeEvent.leader.isLocal()) {
ConfigMember cm = new ConfigMember(v.getString("shardId"), h.getString("hostId"), h.getInt("memberId"));
if (m.getMemberId() == channel.getRemoteMemberId()) { logger.info("[{}-{}] Slave request from {} rejected: in the same shard", gondola.getHostId(), memberId, channel.getRemoteMemberId());
String curMasterShardId = config.getMember(status.masterId).getShardId();
/** * Starts observer mode to remote shard. */ @Override public void startObserving(String shardId, String observedShardId, long timeoutMs) throws ShardManagerException, InterruptedException { boolean success = false; trace("[{}-{}] Try to follow shardId={} as slave...", gondola.getHostId(), gondola.getShard(shardId).getLocalMember().getMemberId(), observedShardId); List<Config.ConfigMember> membersInShard = config.getMembersInShard(observedShardId); for (Config.ConfigMember m : membersInShard) { if (success = setSlave(shardId, m.getMemberId(), timeoutMs / membersInShard.size())) { filter.getChangeLogProcessor().reset(shardId); trace("[{}-{}] Successfully to follow masterId={}", gondola.getHostId(), gondola.getShard(shardId).getLocalMember().getMemberId(), m.getMemberId()); break; } } if (!success) { logger.error("[{}-{}] Failed follow master={}", gondola.getHostId(), gondola.getShard(shardId).getLocalMember().getMemberId(), observedShardId); throw new ShardManagerException(FAILED_START_SLAVE); } observedShards.add(observedShardId); }
/** * By calling this method, the connection's setSocket() method * will eventually get called when a socket connection is established to peerId. */ void reconnect() { if (retry) { logger.info("[{}-{}] Reconnecting socket {} to {}", gondola.getHostId(), memberId, socket, peerId); // If the remote member is not part of this member's shard, this member is assumed to be a slave Config config = gondola.getConfig(); boolean isSlave = config.getMember(memberId).getShardId() != config.getMember(peerId).getShardId(); // Initiate the connection only if this member id is // larger than the remote member or if this member is a // slave. Otherwise, it's assumed that the remote member will initiate the connection. boolean initiateCall = memberId > peerId || isSlave; new SocketCreator(initiateCall).start(); } }
private void sendActionToShard(String shardId, Action action, Object... args) { config.getMembersInShard(shardId).forEach(m -> sendAction(m.getMemberId(), action, args)); }
private void sendActionToAll(Action action, Object... args) { for (Config.ConfigMember m : config.getMembers()) { sendAction(m.getMemberId(), action, args); } }
private boolean isMemberInShard(int memberId, String shardId) { return config.getMember(memberId).getShardId().equals(shardId); }