use of org.apache.geode.IncompatibleSystemException in project geode by apache.
the class DistributionManager method create.
/**
* Creates a new distribution manager and discovers the other members of the distributed system.
* Note that it does not check to see whether or not this VM already has a distribution manager.
*
* @param system The distributed system to which this distribution manager will send messages.
*/
public static DistributionManager create(InternalDistributedSystem system) {
DistributionManager distributionManager = null;
try {
int vmKind;
if (Boolean.getBoolean(InternalLocator.FORCE_LOCATOR_DM_TYPE)) {
// if this DM is starting for a locator, set it to be a locator DM
vmKind = LOCATOR_DM_TYPE;
} else if (isDedicatedAdminVM) {
vmKind = ADMIN_ONLY_DM_TYPE;
} else {
vmKind = NORMAL_DM_TYPE;
}
RemoteTransportConfig transport = new RemoteTransportConfig(system.getConfig(), vmKind);
transport.setIsReconnectingDS(system.isReconnectingDS());
transport.setOldDSMembershipInfo(system.oldDSMembershipInfo());
long start = System.currentTimeMillis();
distributionManager = new DistributionManager(system, transport);
distributionManager.assertDistributionManagerType();
{
InternalDistributedMember id = distributionManager.getDistributionManagerId();
if (!"".equals(id.getName())) {
for (InternalDistributedMember m : (List<InternalDistributedMember>) distributionManager.getViewMembers()) {
if (m.equals(id)) {
// SO once we find ourself break out of this loop.
break;
}
if (id.getName().equals(m.getName())) {
if (distributionManager.getMembershipManager().verifyMember(m, "member is using the name of " + id)) {
throw new IncompatibleSystemException("Member " + id + " could not join this distributed system because the existing member " + m + " used the same name. Set the \"name\" gemfire property to a unique value.");
}
}
}
}
// add ourselves
distributionManager.addNewMember(id);
// ShutdownException could be thrown here
distributionManager.selectElder();
}
// Send out a StartupMessage to the other members.
StartupOperation op = new StartupOperation(distributionManager, transport);
try {
if (!distributionManager.sendStartupMessage(op, true)) {
// we're the first one.
if (distributionManager.getOtherDistributionManagerIds().size() == 0) {
logger.info(LocalizedMessage.create(LocalizedStrings.DistributionManager_DIDNT_HEAR_BACK_FROM_ANY_OTHER_SYSTEM_I_AM_THE_FIRST_ONE));
} else if (transport.isMcastEnabled()) {
// perform a multicast ping test
if (!distributionManager.testMulticast()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.DistributionManager_RECEIVED_NO_STARTUP_RESPONSES_BUT_OTHER_MEMBERS_EXIST_MULTICAST_IS_NOT_RESPONSIVE));
}
}
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
// This is ALWAYS bad; don't consult a CancelCriterion.
throw new InternalGemFireException(LocalizedStrings.DistributionManager_INTERRUPTED_WHILE_WAITING_FOR_FIRST_STARTUPRESPONSEMESSAGE.toLocalizedString(), ex);
} catch (IncompatibleSystemException ex) {
logger.fatal(ex.getMessage(), ex);
throw ex;
} finally {
distributionManager.readyToSendMsgs();
}
if (logger.isInfoEnabled()) {
long delta = System.currentTimeMillis() - start;
Object[] logArgs = new Object[] { distributionManager.getDistributionManagerId(), transport, Integer.valueOf(distributionManager.getOtherDistributionManagerIds().size()), distributionManager.getOtherDistributionManagerIds(), (logger.isInfoEnabled(LogMarker.DM) ? " (VERBOSE, took " + delta + " ms)" : ""), ((distributionManager.getDMType() == ADMIN_ONLY_DM_TYPE) ? " (admin only)" : (distributionManager.getDMType() == LOCATOR_DM_TYPE) ? " (locator)" : "") };
logger.info(LogMarker.DM, LocalizedMessage.create(LocalizedStrings.DistributionManager_DISTRIBUTIONMANAGER_0_STARTED_ON_1_THERE_WERE_2_OTHER_DMS_3_4_5, logArgs));
MembershipLogger.logStartup(distributionManager.getDistributionManagerId());
}
return distributionManager;
} catch (RuntimeException r) {
if (distributionManager != null) {
if (logger.isDebugEnabled()) {
logger.debug("cleaning up incompletely started DistributionManager due to exception", r);
}
distributionManager.uncleanShutdown(true);
}
throw r;
}
}
use of org.apache.geode.IncompatibleSystemException in project geode by apache.
the class DistributionManager method sendStartupMessage.
/**
* Sends a startup message and waits for a response. Returns true if response received; false if
* it timed out or there are no peers.
*/
protected boolean sendStartupMessage(StartupOperation startupOperation, boolean cancelOnTimeout) throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
this.receivedStartupResponse = false;
boolean ok = false;
// Be sure to add ourself to the equivalencies list!
Set equivs = StartupMessage.getMyAddresses(this);
if (equivs == null || equivs.size() == 0) {
// no network interface
equivs = new HashSet();
try {
equivs.add(SocketCreator.getLocalHost());
} catch (UnknownHostException e) {
// can't even get localhost
if (getViewMembers().size() > 1) {
throw new SystemConnectException("Unable to examine network cards and other members exist");
}
}
}
setEquivalentHosts(equivs);
setEnforceUniqueZone(getConfig().getEnforceUniqueHost());
String redundancyZone = getConfig().getRedundancyZone();
if (redundancyZone != null && !redundancyZone.equals("")) {
setEnforceUniqueZone(true);
}
setRedundancyZone(getDistributionManagerId(), redundancyZone);
if (logger.isDebugEnabled()) {
StringBuffer sb = new StringBuffer();
sb.append("Equivalent IPs for this host: ");
Iterator it = equivs.iterator();
while (it.hasNext()) {
InetAddress in = (InetAddress) it.next();
sb.append(in.toString());
if (it.hasNext()) {
sb.append(", ");
}
}
// while
logger.debug(sb);
}
// we need to send this to everyone else; even admin vm
Set allOthers = new HashSet(getViewMembers());
allOthers.remove(getDistributionManagerId());
if (allOthers.isEmpty()) {
// no peers, we are alone.
return false;
}
try {
ok = startupOperation.sendStartupMessage(allOthers, STARTUP_TIMEOUT, equivs, redundancyZone, enforceUniqueZone());
} catch (Exception re) {
throw new SystemConnectException(LocalizedStrings.DistributionManager_ONE_OR_MORE_PEERS_GENERATED_EXCEPTIONS_DURING_CONNECTION_ATTEMPT.toLocalizedString(), re);
}
if (this.rejectionMessage != null) {
throw new IncompatibleSystemException(rejectionMessage);
}
boolean isAdminDM = getId().getVmKind() == DistributionManager.ADMIN_ONLY_DM_TYPE || getId().getVmKind() == DistributionManager.LOCATOR_DM_TYPE || DistributionManager.isDedicatedAdminVM || Boolean.getBoolean(InternalLocator.FORCE_LOCATOR_DM_TYPE);
boolean receivedAny = this.receivedStartupResponse;
if (!ok) {
// someone didn't reply
int unresponsiveCount;
synchronized (unfinishedStartupsLock) {
if (unfinishedStartups == null)
unresponsiveCount = 0;
else
unresponsiveCount = unfinishedStartups.size();
if (unresponsiveCount != 0) {
if (Boolean.getBoolean("DistributionManager.requireAllStartupResponses")) {
throw new SystemConnectException(LocalizedStrings.DistributionManager_NO_STARTUP_REPLIES_FROM_0.toLocalizedString(unfinishedStartups));
}
}
}
// If there are other members, we must receive at least _one_ response
if (allOthers.size() != 0) {
// there exist others
if (!receivedAny) {
// and none responded
StringBuffer sb = new StringBuffer();
Iterator itt = allOthers.iterator();
while (itt.hasNext()) {
Object m = itt.next();
sb.append(m.toString());
if (itt.hasNext())
sb.append(", ");
}
if (DEBUG_NO_ACKNOWLEDGEMENTS) {
printStacks(allOthers, false);
}
throw new SystemConnectException(LocalizedStrings.DistributionManager_RECEIVED_NO_CONNECTION_ACKNOWLEDGMENTS_FROM_ANY_OF_THE_0_SENIOR_CACHE_MEMBERS_1.toLocalizedString(new Object[] { Integer.toString(allOthers.size()), sb.toString() }));
}
// and none responded
}
// there exist others
InternalDistributedMember e = getElderId();
if (e != null) {
// an elder exists
boolean unresponsiveElder;
synchronized (unfinishedStartupsLock) {
if (unfinishedStartups == null)
unresponsiveElder = false;
else
unresponsiveElder = unfinishedStartups.contains(e);
}
if (unresponsiveElder) {
logger.warn(LocalizedMessage.create(LocalizedStrings.DistributionManager_FORCING_AN_ELDER_JOIN_EVENT_SINCE_A_STARTUP_RESPONSE_WAS_NOT_RECEIVED_FROM_ELDER__0_, e));
handleManagerStartup(e);
}
}
// an elder exists
}
// someone didn't reply
return receivedAny;
}
use of org.apache.geode.IncompatibleSystemException in project geode by apache.
the class DistributedMemberDUnitTest method testTwoMembersSameName.
@Test
public void testTwoMembersSameName() {
// or assertion on # members fails when run-dunit-tests
disconnectFromDS();
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
public void run() {
Properties config = new Properties();
config.setProperty(NAME, "name0");
getSystem(config);
}
});
Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {
public void run() {
Properties config = new Properties();
config.setProperty(NAME, "name1");
getSystem(config);
}
});
Host.getHost(0).getVM(2).invoke(new SerializableRunnable() {
public void run() {
Properties config = new Properties();
config.setProperty(NAME, "name0");
try {
getSystem(config);
fail("expected IncompatibleSystemException");
} catch (IncompatibleSystemException expected) {
}
}
});
}
Aggregations