@Override public ReplicationSession createReplicationSession(Session session, Collection<NetEndpoint> replicationEndpoints, Boolean remote) { return NetEndpointManagerHolder.get().createReplicationSession(session, replicationEndpoints, remote); }
@Override public NetEndpoint getEndpoint(String hostId) { return NetEndpointManagerHolder.get().getEndpoint(hostId); }
@Override public String getHostId(NetEndpoint endpoint) { return NetEndpointManagerHolder.get().getHostId(endpoint); }
liveMembers = new HashSet<>(hostIds.length); for (String hostId : hostIds) { liveMembers.add(m.getEndpoint(hostId)); List<NetEndpoint> endpoints = m.getReplicationEndpoints(db, new HashSet<>(0), liveMembers); if (!endpoints.isEmpty()) { initReplicationEndpoints = new ArrayList<>(endpoints.size()); for (NetEndpoint e : endpoints) { String hostId = m.getHostId(e); initReplicationEndpoints.add(hostId); int i = 0; for (NetEndpoint e : liveMembers) { String hostId = m.getHostId(e); sessions[i++] = currentSession.getNestedSession(hostId, !NetEndpoint.getLocalP2pEndpoint().equals(e)); rs.setRpcTimeout(m.getRpcTimeout()); Command c = null; try {
public static int executeDatabaseStatement(IDatabase db, Session currentSession, StatementBase statement) { NetEndpointManager m = NetEndpointManagerHolder.get(); Set<NetEndpoint> liveMembers = m.getLiveEndpoints(); NetEndpoint localEndpoint = NetEndpoint.getLocalP2pEndpoint(); liveMembers.remove(localEndpoint); int i = 0; for (NetEndpoint e : liveMembers) { String hostId = m.getHostId(e); sessions[i++] = currentSession.getNestedSession(hostId, true); ReplicationSession rs = m.createReplicationSession(currentSession, sessions); Command c = null; try {
private void rewriteSql(boolean toReplicationMode) { if (session.isRoot()) { oldHostIds = db.getHostIds(); if (parameters != null && parameters.containsKey("hostIds")) { newHostIds = StringUtils.arraySplit(parameters.get("hostIds"), ',', true); } else { if (toReplicationMode) newHostIds = NetEndpointManagerHolder.get().getReplicationEndpoints(db); else newHostIds = NetEndpointManagerHolder.get().getShardingEndpoints(db); } String hostIds = StringUtils.arrayCombine(oldHostIds, ',') + "," + StringUtils.arrayCombine(newHostIds, ','); db.getParameters().put("hostIds", hostIds); rewriteSql(); } else { if (super.isTargetEndpoint(db)) { oldHostIds = db.getHostIds(); HashSet<String> oldSet = new HashSet<>(Arrays.asList(oldHostIds)); if (parameters != null && parameters.containsKey("hostIds")) { String[] hostIds = StringUtils.arraySplit(parameters.get("hostIds"), ',', true); HashSet<String> newSet = new HashSet<>(Arrays.asList(hostIds)); newSet.removeAll(oldSet); newHostIds = newSet.toArray(new String[0]); } else { DbException.throwInternalError(); } } } }
@Override public List<NetEndpoint> getReplicationEndpoints(Set<NetEndpoint> oldReplicationEndpoints, Set<NetEndpoint> candidateEndpoints) { return NetEndpointManagerHolder.get().getReplicationEndpoints(this, oldReplicationEndpoints, candidateEndpoints); } }
newDB.setRunMode(runMode); if (!parameters.containsKey("hostIds")) { String[] hostIds = NetEndpointManagerHolder.get().assignEndpoints(newDB); if (hostIds != null && hostIds.length > 0) newDB.getParameters().put("hostIds", StringUtils.arrayCombine(hostIds, ','));
@Override public ReplicationSession createReplicationSession(Session session, Collection<NetEndpoint> replicationEndpoints) { return NetEndpointManagerHolder.get().createReplicationSession(session, replicationEndpoints); }