mirror of https://github.com/apache/cassandra
Merge commit '3c55732fa414c7835536dc42ff489461a7441bfe' into cassandra-2.2
This commit is contained in:
commit
0b479a7f3e
|
@ -23,6 +23,7 @@
|
|||
* Disable reloading of GossipingPropertyFileSnitch (CASSANDRA-9474)
|
||||
* Verify tables in pseudo-system keyspaces at startup (CASSANDRA-10761)
|
||||
Merged from 2.1:
|
||||
* Fix bad gossip generation seen in long-running clusters (CASSANDRA-10969)
|
||||
* Avoid NPE when incremental repair fails (CASSANDRA-10909)
|
||||
* Unmark sstables compacting once they are done in cleanup/scrub/upgradesstables (CASSANDRA-10829)
|
||||
* Allow simultaneous bootstrapping with strict consistency when no vnodes are used (CASSANDRA-11005)
|
||||
|
|
|
@ -87,8 +87,8 @@ public class Gossiper implements IFailureDetectionEventListener, GossiperMBean
|
|||
|
||||
public static final long aVeryLongTime = 259200 * 1000; // 3 days
|
||||
|
||||
/** Maximum difference in generation and version values we are willing to accept about a peer */
|
||||
private static final long MAX_GENERATION_DIFFERENCE = 86400 * 365;
|
||||
// Maximimum difference between generation value and local time we are willing to accept about a peer
|
||||
static final int MAX_GENERATION_DIFFERENCE = 86400 * 365;
|
||||
private long fatClientTimeout;
|
||||
private final Random random = new Random();
|
||||
private final Comparator<InetAddress> inetcomparator = new Comparator<InetAddress>()
|
||||
|
@ -1101,13 +1101,15 @@ public class Gossiper implements IFailureDetectionEventListener, GossiperMBean
|
|||
{
|
||||
int localGeneration = localEpStatePtr.getHeartBeatState().getGeneration();
|
||||
int remoteGeneration = remoteState.getHeartBeatState().getGeneration();
|
||||
long localTime = System.currentTimeMillis()/1000;
|
||||
if (logger.isTraceEnabled())
|
||||
logger.trace("{} local generation {}, remote generation {}", ep, localGeneration, remoteGeneration);
|
||||
|
||||
if (localGeneration != 0 && remoteGeneration > localGeneration + MAX_GENERATION_DIFFERENCE)
|
||||
// We measure generation drift against local time, based on the fact that generation is initialized by time
|
||||
if (remoteGeneration > localTime + MAX_GENERATION_DIFFERENCE)
|
||||
{
|
||||
// assume some peer has corrupted memory and is broadcasting an unbelievable generation about another peer (or itself)
|
||||
logger.warn("received an invalid gossip generation for peer {}; local generation = {}, received generation = {}", ep, localGeneration, remoteGeneration);
|
||||
logger.warn("received an invalid gossip generation for peer {}; local time = {}, received generation = {}", ep, localTime, remoteGeneration);
|
||||
}
|
||||
else if (remoteGeneration > localGeneration)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cassandra.gms;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.cassandra.SchemaLoader;
|
||||
import org.apache.cassandra.Util;
|
||||
import org.apache.cassandra.dht.IPartitioner;
|
||||
import org.apache.cassandra.dht.RandomPartitioner;
|
||||
import org.apache.cassandra.dht.Token;
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.cassandra.locator.TokenMetadata;
|
||||
import org.apache.cassandra.service.StorageService;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class GossiperTest
|
||||
{
|
||||
static final IPartitioner partitioner = new RandomPartitioner();
|
||||
StorageService ss = StorageService.instance;
|
||||
TokenMetadata tmd = StorageService.instance.getTokenMetadata();
|
||||
ArrayList<Token> endpointTokens = new ArrayList<>();
|
||||
ArrayList<Token> keyTokens = new ArrayList<>();
|
||||
List<InetAddress> hosts = new ArrayList<>();
|
||||
List<UUID> hostIds = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
tmd.clearUnsafe();
|
||||
};
|
||||
|
||||
@Test
|
||||
public void testLargeGenerationJump() throws UnknownHostException, InterruptedException
|
||||
{
|
||||
Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 2);
|
||||
InetAddress remoteHostAddress = hosts.get(1);
|
||||
|
||||
EndpointState initialRemoteState = Gossiper.instance.getEndpointStateForEndpoint(remoteHostAddress);
|
||||
HeartBeatState initialRemoteHeartBeat = initialRemoteState.getHeartBeatState();
|
||||
|
||||
//Util.createInitialRing should have initialized remoteHost's HeartBeatState's generation to 1
|
||||
assertEquals(initialRemoteHeartBeat.getGeneration(), 1);
|
||||
|
||||
HeartBeatState proposedRemoteHeartBeat = new HeartBeatState(initialRemoteHeartBeat.getGeneration() + Gossiper.MAX_GENERATION_DIFFERENCE + 1);
|
||||
EndpointState proposedRemoteState = new EndpointState(proposedRemoteHeartBeat);
|
||||
|
||||
Gossiper.instance.applyStateLocally(ImmutableMap.of(remoteHostAddress, proposedRemoteState));
|
||||
|
||||
//The generation should have been updated because it isn't over Gossiper.MAX_GENERATION_DIFFERENCE in the future
|
||||
HeartBeatState actualRemoteHeartBeat = Gossiper.instance.getEndpointStateForEndpoint(remoteHostAddress).getHeartBeatState();
|
||||
assertEquals(proposedRemoteHeartBeat.getGeneration(), actualRemoteHeartBeat.getGeneration());
|
||||
|
||||
//Propose a generation 10 years in the future - this should be rejected.
|
||||
HeartBeatState badProposedRemoteHeartBeat = new HeartBeatState((int) (System.currentTimeMillis()/1000) + Gossiper.MAX_GENERATION_DIFFERENCE * 10);
|
||||
EndpointState badProposedRemoteState = new EndpointState(badProposedRemoteHeartBeat);
|
||||
|
||||
Gossiper.instance.applyStateLocally(ImmutableMap.of(remoteHostAddress, badProposedRemoteState));
|
||||
|
||||
actualRemoteHeartBeat = Gossiper.instance.getEndpointStateForEndpoint(remoteHostAddress).getHeartBeatState();
|
||||
|
||||
//The generation should not have been updated because it is over Gossiper.MAX_GENERATION_DIFFERENCE in the future
|
||||
assertEquals(proposedRemoteHeartBeat.getGeneration(), actualRemoteHeartBeat.getGeneration());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue