/** * Return true if this node is no longer configured as the designated * primary under the new configuration. */ @Override public boolean shouldEndArbitration(ReplicationMutableConfig newConfig) { return (!newConfig.getDesignatedPrimary()); } }
private void copyMutablePropsTo(Properties from, ReplicationMutableConfig toConfig) { Enumeration<?> propNames = from.propertyNames(); while (propNames.hasMoreElements()) { String paramName = (String) propNames.nextElement(); ConfigParam param = EnvironmentParams.SUPPORTED_PARAMS.get(paramName); if (param != null && param.isForReplication() && param.isMutable()) { toConfig.setConfigParam(paramName, from.getProperty(paramName)); } } }
/** * If {@code isPrimary} is true, designate this node as a Primary. This * setting only takes effect for electable nodes. The application must * ensure that exactly one electable node is designated to be a Primary at * any given time. Primary node configuration is only a concern when the * group has two electable nodes, and there cannot be a simple * majority. See the overview on <a href= * "{@docRoot}/../ReplicationGuide/lifecycle.html#twonode">configuring two * node groups</a>. * * @param isPrimary true if this node is to be made the Primary * * @return this */ public ReplicationMutableConfig setDesignatedPrimary(boolean isPrimary) { setDesignatedPrimaryVoid(isPrimary); return this; }
/** * Fills in the properties calculated by the environment to the given * config object. */ void fillInEnvironmentGeneratedProps(RepImpl repImpl) { props.put(RepParams.DESIGNATED_PRIMARY.getName(), Boolean.toString(repImpl.isDesignatedPrimary())); props.put(RepParams.NODE_PRIORITY.getName(), Integer.toString(getNodePriority())); }
int getElectableGroupSizeOverride() { ReplicationMutableConfig repConfig = getEnvironment().getRepMutableConfig(); return repConfig.getElectableGroupSizeOverride(); }
/** * Sets the size used to determine the number of electable nodes. * * @param override the number of electable nodes. A value of zero means * that the number of electable nodes is determined as usual, that is, from * the contents of the group metadata. * * @return this * * @see #ELECTABLE_GROUP_SIZE_OVERRIDE */ public ReplicationMutableConfig setElectableGroupSizeOverride(int override) { setElectableGroupSizeOverrideVoid(override); return this; }
/** * Returns a copy of this configuration object. */ @Override public ReplicationConfig clone() { try { ReplicationConfig copy = (ReplicationConfig) super.clone(); copy.setRepNetConfig(getRepNetConfig().clone()); return copy; } catch (CloneNotSupportedException willNeverOccur) { return null; } }
private Environment createEnvironment(final EnvironmentConfig config) throws Exception { final Environment env; if (_ha) { final ReplicationConfig repConfig = (ReplicationConfig) ReplicationConfig.DEFAULT .setNodeHostPort(_nodeHost) .setGroupName(_groupName) .setNodeName(_nodeName) .setDesignatedPrimary(true) .setElectableGroupSizeOverride(1); env = new ReplicatedEnvironment(new File(_storePath), repConfig, config); } else { env = new Environment(new File(_storePath), config); } return env; }
public void setRepMutableConfig(ReplicationMutableConfig config) throws DatabaseException { /* Clone the current config. */ RepConfigManager repConfigManager = (RepConfigManager) configManager; ReplicationConfig newConfig = repConfigManager.makeReplicationConfig(); /* Copy in the mutable props. */ config.copyMutablePropsTo(newConfig); repConfigManager = new RepConfigManager (configManager.getEnvironmentConfig(), newConfig); /* * Update the current config and notify observers. The config manager * is replaced with a new instance that uses the new configuration. * This avoids synchronization issues: other threads that have a * reference to the old configuration object are not impacted. * * Notify listeners in reverse order of registration so that the * environment listener is notified last and can start daemon threads * after they are configured. */ for (int i = repConfigObservers.size() - 1; i >= 0; i -= 1) { RepEnvConfigObserver o = repConfigObservers.get(i); o.repEnvConfigUpdate(repConfigManager, newConfig); } }
/** * @throws EnvironmentFailureException if an unexpected, internal or * environment-wide failure occurs. * * @throws IllegalStateException if this handle or the underlying * environment has already been closed. */ public ReplicationMutableConfig getRepMutableConfig() throws DatabaseException { final RepImpl repImpl = checkOpen(); try { final ReplicationMutableConfig config = repImpl.cloneRepMutableConfig(); config.fillInEnvironmentGeneratedProps(repImpl); return config; } catch (Error E) { repImpl.invalidate(E); throw E; } }
int getPriority() { ReplicationMutableConfig repConfig = getEnvironment().getRepMutableConfig(); return repConfig.getNodePriority(); }
@Override public void repEnvConfigUpdate(RepConfigManager configMgr, ReplicationMutableConfig newConfig) throws DatabaseException { allowArbiterAck = configMgr.getBoolean(RepParams.ALLOW_ARBITER_ACK); if (repNode == null) { return; } repNode.getArbiter().processConfigChange(newConfig); repNode.getElectionQuorum().setElectableGroupSizeOverride (newConfig.getElectableGroupSizeOverride()); /* Account for mutation of deprecated HA LogFlusher params. */ getLogFlusher().configFlushTask(configMgr); repNode.getReplica().getDbCache().setConfig(configMgr); }
public boolean isDesignatedPrimary() { return getEnvironment().getRepMutableConfig().getDesignatedPrimary(); }
final ReplicationMutableConfig newConfig = oldConfig.setConfigParam(paramName, String.valueOf(newValue)); environment.setRepMutableConfig(newConfig);