Skip to content

Commit

Permalink
IGNITE-23830 Remove setForceServerMode (#11757)
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov authored Dec 19, 2024
1 parent d04d9a6 commit 59114d3
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,6 @@ public IgniteConfiguration setCacheConfiguration(CacheConfiguration... cacheCfg)
* {@link DiscoverySpi} in client mode if this property is {@code true}.
*
* @return Client mode flag.
* @see TcpDiscoverySpi#setForceServerMode(boolean)
*/
public Boolean isClientMode() {
return clientMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1251,10 +1251,6 @@ public void start(

assert locNode.isClient();

if (!ctx.discovery().reconnectSupported())
throw new IgniteCheckedException("Client node in forceServerMode " +
"is not allowed to reconnect to the cluster and will be stopped.");

if (log.isDebugEnabled())
log.debug("Failed to start node components on node start, will wait for reconnect: " + e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
import org.apache.ignite.spi.discovery.DiscoverySpiNodeAuthenticator;
import org.apache.ignite.spi.discovery.DiscoverySpiOrderSupport;
import org.apache.ignite.spi.discovery.IgniteDiscoveryThread;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode;
import org.apache.ignite.spi.systemview.view.ClusterNodeView;
import org.apache.ignite.spi.systemview.view.NodeAttributeView;
Expand Down Expand Up @@ -477,13 +476,6 @@ private void updateClientNodes(UUID leftNodeId) {
}
}

/** {@inheritDoc} */
@Override protected void onKernalStart0() throws IgniteCheckedException {
if ((getSpi() instanceof TcpDiscoverySpi) && Boolean.TRUE.equals(ctx.config().isClientMode()) && !getSpi().isClientMode())
ctx.performance().add("Enable client mode for TcpDiscoverySpi " +
"(set TcpDiscoverySpi.forceServerMode to false)");
}

/** {@inheritDoc} */
@Override public void start() throws IgniteCheckedException {
ctx.addNodeAttribute(ATTR_OFFHEAP_SIZE, requiredOffheap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ else if (msg instanceof UserAuthenticateResponseMessage)
if (ctx.clientNode()) {
if (ctx.discovery().aliveServerNodes().isEmpty()) {
throw new IgniteAccessControlException("No alive server node was found to which the authentication" +
" operation could be delegated. It is possible that the client node has been started with the" +
" \"forceServerMode\" flag enabled and no server node had been started yet.");
" operation could be delegated.");
}

AuthenticateFuture fut;
Expand Down Expand Up @@ -631,8 +630,7 @@ private ClusterNode coordinator() {
if (res == null
&& !ctx.discovery().allNodes().isEmpty()
&& ctx.discovery().aliveServerNodes().isEmpty()) {
U.warn(log, "Cannot find the server coordinator node. "
+ "Possible a client is started with forceServerMode=true.");
U.warn(log, "Cannot find the server coordinator node.");
}
else
assert res != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
import org.apache.ignite.lang.IgniteFuture;
import org.apache.ignite.lang.IgniteInClosure;
import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.cache.CacheRebalanceMode.NONE;
Expand Down Expand Up @@ -223,9 +222,6 @@ boolean onCustomEvent(CacheAffinityChangeMessage msg) {

boolean isClient = cctx.discovery().localNode().isClient();

if (cctx.kernalContext().config().getDiscoverySpi() instanceof TcpDiscoverySpi)
isClient &= !((TcpDiscoverySpi)cctx.kernalContext().config().getDiscoverySpi()).isForceServerMode();

// Skip message if affinity was already recalculated.
// Client node should just accept the flag from the mutated message.
boolean exchangeNeeded = (isClient) ? msg.exchangeNeeded() :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,6 @@ else if (ipFinderType == 2) {
disco.setNetworkTimeout(in.readLong());
disco.setJoinTimeout(in.readLong());

disco.setForceServerMode(in.readBoolean());
disco.setClientReconnectDisabled(in.readBoolean());
disco.setLocalAddress(in.readString());
disco.setReconnectCount(in.readInt());
Expand Down Expand Up @@ -1627,7 +1626,6 @@ private static void writeDiscoveryConfiguration(BinaryRawWriter w, DiscoverySpi
w.writeLong(tcp.getNetworkTimeout());
w.writeLong(tcp.getJoinTimeout());

w.writeBoolean(tcp.isForceServerMode());
w.writeBoolean(tcp.isClientReconnectDisabled());
w.writeString(tcp.getLocalAddress());
w.writeInt(tcp.getReconnectCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,6 @@ class ClientImpl extends TcpDiscoveryImpl {
sockReader = new SocketReader();
sockReader.start();

if (spi.ipFinder.isShared() && spi.isForceServerMode())
registerLocalNodeAddress();

msgWorker = new MessageWorker(log);

new IgniteSpiThread(msgWorker.igniteInstanceName(), msgWorker.name(), log) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,50 @@ else if (log.isDebugEnabled())
log.debug("Received metrics from unknown node: " + nodeId);
}

/**
* @throws IgniteSpiException If failed.
*/
private final void registerLocalNodeAddress() throws IgniteSpiException {
long spiJoinTimeout = spi.getJoinTimeout();

// Make sure address registration succeeded.
// ... but limit it if join timeout is configured.
long startNanos = spiJoinTimeout > 0 ? System.nanoTime() : 0;

while (true) {
try {
spi.ipFinder.initializeLocalAddresses(
U.resolveAddresses(spi.getAddressResolver(), locNode.socketAddresses()));

// Success.
break;
}
catch (IllegalStateException e) {
throw new IgniteSpiException("Failed to register local node address with IP finder: " +
locNode.socketAddresses(), e);
}
catch (IgniteSpiException e) {
LT.error(log, e, "Failed to register local node address in IP finder on start " +
"(retrying every " + spi.getReconnectDelay() + " ms; " +
"change 'reconnectDelay' to configure the frequency of retries).");
}

if (spiJoinTimeout > 0 && U.millisSinceNanos(startNanos) > spiJoinTimeout)
throw new IgniteSpiException(
"Failed to register local addresses with IP finder within join timeout " +
"(make sure IP finder configuration is correct, and operating system firewalls are disabled " +
"on all host machines, or consider increasing 'joinTimeout' configuration property) " +
"[joinTimeout=" + spiJoinTimeout + ']');

try {
U.sleep(spi.getReconnectDelay());
}
catch (IgniteInterruptedCheckedException e) {
throw new IgniteSpiException("Thread has been interrupted.", e);
}
}
}

/**
* <strong>FOR TEST ONLY!!!</strong>
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.ignite.cluster.ClusterMetrics;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.processors.tracing.NoopTracing;
import org.apache.ignite.internal.processors.tracing.Tracing;
import org.apache.ignite.internal.util.typedef.T2;
Expand Down Expand Up @@ -384,50 +383,6 @@ public abstract void updateMetrics(UUID nodeId,
Map<Integer, CacheMetrics> cacheMetrics,
long tsNanos);

/**
* @throws IgniteSpiException If failed.
*/
protected final void registerLocalNodeAddress() throws IgniteSpiException {
long spiJoinTimeout = spi.getJoinTimeout();

// Make sure address registration succeeded.
// ... but limit it if join timeout is configured.
long startNanos = spiJoinTimeout > 0 ? System.nanoTime() : 0;

while (true) {
try {
spi.ipFinder.initializeLocalAddresses(
U.resolveAddresses(spi.getAddressResolver(), locNode.socketAddresses()));

// Success.
break;
}
catch (IllegalStateException e) {
throw new IgniteSpiException("Failed to register local node address with IP finder: " +
locNode.socketAddresses(), e);
}
catch (IgniteSpiException e) {
LT.error(log, e, "Failed to register local node address in IP finder on start " +
"(retrying every " + spi.getReconnectDelay() + " ms; " +
"change 'reconnectDelay' to configure the frequency of retries).");
}

if (spiJoinTimeout > 0 && U.millisSinceNanos(startNanos) > spiJoinTimeout)
throw new IgniteSpiException(
"Failed to register local addresses with IP finder within join timeout " +
"(make sure IP finder configuration is correct, and operating system firewalls are disabled " +
"on all host machines, or consider increasing 'joinTimeout' configuration property) " +
"[joinTimeout=" + spiJoinTimeout + ']');

try {
U.sleep(spi.getReconnectDelay());
}
catch (IgniteInterruptedCheckedException e) {
throw new IgniteSpiException("Thread has been interrupted.", e);
}
}
}

/**
* @param ackTimeout Acknowledgement timeout.
* @return {@code True} if acknowledgement timeout is less or equal to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@
* TcpDiscoverySpi starts in client mode as well. In this case node does not take its place in the ring,
* but it connects to random node in the ring (IP taken from IP finder configured) and
* use it as a router for discovery traffic.
* Therefore slow client node or its shutdown will not affect whole cluster. If TcpDiscoverySpi
* needs to be started in server mode regardless of {@link IgniteConfiguration#clientMode},
* {@link #forceSrvMode} should be set to true.
* Therefore slow client node or its shutdown will not affect whole cluster.
* <p>
* At startup SPI tries to send messages to random IP taken from
* {@link TcpDiscoveryIpFinder} about self start (stops when send succeeds)
Expand Down Expand Up @@ -191,7 +189,6 @@
* <li>Thread priority for threads started by SPI (see {@link #setThreadPriority(int)})</li>
* <li>IP finder clean frequency (see {@link #setIpFinderCleanFrequency(long)})</li>
* <li>Statistics print frequency (see {@link #setStatisticsPrintFrequency(long)}</li>
* <li>Force server mode (see {@link #setForceServerMode(boolean)}</li>
* </ul>
* <h2 class="header">Java Example</h2>
* <pre name="code" class="java">
Expand Down Expand Up @@ -444,9 +441,6 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements IgniteDiscovery
/** */
protected TcpDiscoveryImpl impl;

/** */
private boolean forceSrvMode;

/** */
private boolean clientReconnectDisabled;

Expand Down Expand Up @@ -564,36 +558,6 @@ public void dumpDebugInfo() {
return impl instanceof ClientImpl;
}

/**
* If {@code true} TcpDiscoverySpi will started in server mode regardless
* of {@link IgniteConfiguration#isClientMode()}
*
* @return forceServerMode flag.
* @deprecated Will be removed at 3.0.
*/
@Deprecated
public boolean isForceServerMode() {
return forceSrvMode;
}

/**
* Sets force server mode flag.
* <p>
* If {@code true} TcpDiscoverySpi is started in server mode regardless
* of {@link IgniteConfiguration#isClientMode()}.
*
* @param forceSrvMode forceServerMode flag.
* @return {@code this} for chaining.
* @deprecated Will be removed at 3.0.
*/
@IgniteSpiConfiguration(optional = true)
@Deprecated
public TcpDiscoverySpi setForceServerMode(boolean forceSrvMode) {
this.forceSrvMode = forceSrvMode;

return this;
}

/**
* If {@code true} client does not try to reconnect after
* server detected client node failure.
Expand Down Expand Up @@ -2263,7 +2227,7 @@ protected void initializeImpl() {

initFailureDetectionTimeout();

if (!forceSrvMode && (Boolean.TRUE.equals(ignite.configuration().isClientMode()))) {
if (Boolean.TRUE.equals(ignite.configuration().isClientMode())) {
if (ackTimeout == 0)
ackTimeout = DFLT_ACK_TIMEOUT_CLIENT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import org.apache.ignite.spi.IgniteSpiConfiguration;
import org.apache.ignite.spi.IgniteSpiContext;
import org.apache.ignite.spi.IgniteSpiException;
import org.apache.ignite.spi.discovery.DiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;

/**
* IP finder interface implementation adapter.
Expand Down Expand Up @@ -95,31 +93,6 @@ public TcpDiscoveryIpFinderAdapter setShared(boolean shared) {
// No-op.
}

/**
* @return {@code True} if TCP discovery works in client mode.
* @deprecated Since 2.8. May return incorrect value if client and server nodes shares same {@link
* TcpDiscoveryIpFinder} instance.
*/
@Deprecated
protected boolean discoveryClientMode() {
boolean clientMode;

Ignite ignite0 = ignite;

if (ignite0 != null) { // Can be null if used in tests without starting Ignite.
DiscoverySpi discoSpi = ignite0.configuration().getDiscoverySpi();

if (!(discoSpi instanceof TcpDiscoverySpi))
throw new IgniteSpiException("TcpDiscoveryIpFinder should be used with TcpDiscoverySpi: " + discoSpi);

clientMode = ignite0.configuration().isClientMode() && !((TcpDiscoverySpi)discoSpi).isForceServerMode();
}
else
clientMode = false;

return clientMode;
}

/**
* @return SPI context.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ internal TcpDiscoverySpi(IBinaryRawReader reader)
NetworkTimeout = reader.ReadLongAsTimespan();
JoinTimeout = reader.ReadLongAsTimespan();

ForceServerMode = reader.ReadBoolean();
ClientReconnectDisabled = reader.ReadBoolean();
LocalAddress = reader.ReadString();
ReconnectCount = reader.ReadInt();
Expand Down Expand Up @@ -160,12 +159,6 @@ internal TcpDiscoverySpi(IBinaryRawReader reader)
/// </summary>
public TimeSpan JoinTimeout { get; set; }

/// <summary>
/// Gets or sets a value indicating whether TcpDiscoverySpi is started in server mode
/// regardless of <see cref="IgniteConfiguration.ClientMode"/> setting.
/// </summary>
public bool ForceServerMode { get; set; }

/// <summary>
/// Gets or sets a value indicating whether client does not try to reconnect after
/// server detected client node failure.
Expand Down Expand Up @@ -247,7 +240,6 @@ internal void Write(IBinaryRawWriter writer)
writer.WriteLong((long) NetworkTimeout.TotalMilliseconds);
writer.WriteLong((long) JoinTimeout.TotalMilliseconds);

writer.WriteBoolean(ForceServerMode);
writer.WriteBoolean(ClientReconnectDisabled);
writer.WriteString(LocalAddress);
writer.WriteInt(ReconnectCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1125,13 +1125,6 @@
<xs:documentation>Whether client does not try to reconnect after server detected client node failure.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="forceServerMode" type="xs:boolean">
<xs:annotation>
<xs:documentation>
Whether TcpDiscoveryspi is started in server mode regardless of IgniteConfiguration.ClientMode setting.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ipFinderCleanFrequency" type="xs:string">
<xs:annotation>
<xs:documentation>IP finder clean frequency.</xs:documentation>
Expand Down

0 comments on commit 59114d3

Please sign in to comment.