use of org.apache.cassandra.service.StorageService in project cassandra by apache.
the class GossipSettlesTest method testGossipSettles.
@Test
public void testGossipSettles() throws Throwable {
/* Use withSubnet(1) to prove seed provider is set correctly - without the fix to pass a seed provider, this test fails */
try (Cluster cluster = builder().withNodes(3).withConfig(config -> config.with(GOSSIP).with(NETWORK)).withSubnet(1).start()) {
// Verify the 4.0 WithPort versions of status reporting methods match their InetAddress
// counterparts. Disable Gossip first to prevent any bump in heartbeats that would
// invalidate the comparison. Compare the newer WithPort versions by adding the
// storage port to IP addresses in keys/values/strings as appropriate.
cluster.forEach(i -> i.runOnInstance(() -> {
Gossiper.instance.stop();
}));
cluster.get(1).runOnInstance(() -> {
// First prove that the storage port is added
Assert.assertEquals("stuff 127.0.0.1:7012 morestuff 127.0.0.2:7012", addStoragePortToIP("stuff 127.0.0.1 morestuff 127.0.0.2"));
FailureDetector fd = ((FailureDetector) FailureDetector.instance);
Assert.assertEquals(addStoragePortToInstanceName(fd.getAllEndpointStates(false)), fd.getAllEndpointStates(true));
Assert.assertEquals(addPortToKeys(fd.getSimpleStates()), fd.getSimpleStatesWithPort());
StorageProxy sp = StorageProxy.instance;
Assert.assertEquals(addPortToSchemaVersions(sp.getSchemaVersions()), sp.getSchemaVersionsWithPort());
StorageService ss = StorageService.instance;
Assert.assertEquals(addPortToValues(ss.getTokenToEndpointMap()), ss.getTokenToEndpointWithPortMap());
Assert.assertEquals(addPortToKeys(ss.getEndpointToHostId()), ss.getEndpointWithPortToHostId());
Assert.assertEquals(addPortToValues(ss.getHostIdToEndpoint()), ss.getHostIdToEndpointWithPort());
Assert.assertEquals(addPortToKeys(ss.getLoadMap()), ss.getLoadMapWithPort());
Assert.assertEquals(addPortToList(ss.getLiveNodes()), ss.getLiveNodesWithPort());
List<String> naturalEndpointsAddedPort = ss.getNaturalEndpoints(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, SystemDistributedKeyspace.VIEW_BUILD_STATUS, "dummy").stream().map(e -> addStoragePortToIP(e.getHostAddress())).collect(Collectors.toList());
Assert.assertEquals(naturalEndpointsAddedPort, ss.getNaturalEndpointsWithPort(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, SystemDistributedKeyspace.VIEW_BUILD_STATUS, "dummy"));
naturalEndpointsAddedPort = ss.getNaturalEndpoints(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, ByteBufferUtil.EMPTY_BYTE_BUFFER).stream().map(e -> addStoragePortToIP(e.getHostAddress())).collect(Collectors.toList());
Assert.assertEquals(naturalEndpointsAddedPort, ss.getNaturalEndpointsWithPort(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, ByteBufferUtil.EMPTY_BYTE_BUFFER));
// Difference in key type... convert to String and add the port to the older format
Map<String, Float> getOwnershipKeyAddedPort = ss.getOwnership().entrySet().stream().collect(Collectors.<Map.Entry<InetAddress, Float>, String, Float>toMap(e -> addStoragePortToIP(e.getKey().toString()), Map.Entry::getValue));
Assert.assertEquals(getOwnershipKeyAddedPort, ss.getOwnershipWithPort());
MessagingService ms = MessagingService.instance();
Assert.assertEquals(addPortToKeys(ms.getTimeoutsPerHost()), ms.getTimeoutsPerHostWithPort());
Assert.assertEquals(addPortToKeys(ms.getLargeMessagePendingTasks()), ms.getLargeMessagePendingTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getLargeMessageCompletedTasks()), ms.getLargeMessageCompletedTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getLargeMessageDroppedTasks()), ms.getLargeMessageDroppedTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getSmallMessagePendingTasks()), ms.getSmallMessagePendingTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getSmallMessageCompletedTasks()), ms.getSmallMessageCompletedTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getSmallMessageDroppedTasks()), ms.getSmallMessageDroppedTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getGossipMessagePendingTasks()), ms.getGossipMessagePendingTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getGossipMessageCompletedTasks()), ms.getGossipMessageCompletedTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getGossipMessageDroppedTasks()), ms.getGossipMessageDroppedTasksWithPort());
});
}
}
use of org.apache.cassandra.service.StorageService in project cassandra by apache.
the class CleanupTransientTest method setup.
@BeforeClass
public static void setup() throws Exception {
DatabaseDescriptor.daemonInitialization();
DatabaseDescriptor.setTransientReplicationEnabledUnsafe(true);
oldPartitioner = StorageService.instance.setPartitionerUnsafe(partitioner);
SchemaLoader.prepareServer();
SchemaLoader.createKeyspace(KEYSPACE1, KeyspaceParams.simple("2/1"), SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD1), SchemaLoader.compositeIndexCFMD(KEYSPACE1, CF_INDEXED1, true));
StorageService ss = StorageService.instance;
final int RING_SIZE = 2;
TokenMetadata tmd = ss.getTokenMetadata();
tmd.clearUnsafe();
ArrayList<Token> endpointTokens = new ArrayList<>();
ArrayList<Token> keyTokens = new ArrayList<>();
List<InetAddressAndPort> hosts = new ArrayList<>();
List<UUID> hostIds = new ArrayList<>();
endpointTokens.add(RandomPartitioner.MINIMUM);
endpointTokens.add(RandomPartitioner.instance.midpoint(RandomPartitioner.MINIMUM, new RandomPartitioner.BigIntegerToken(RandomPartitioner.MAXIMUM)));
Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, RING_SIZE);
PendingRangeCalculatorService.instance.blockUntilFinished();
DatabaseDescriptor.setEndpointSnitch(new AbstractNetworkTopologySnitch() {
@Override
public String getRack(InetAddressAndPort endpoint) {
return "RC1";
}
@Override
public String getDatacenter(InetAddressAndPort endpoint) {
return "DC1";
}
});
}
use of org.apache.cassandra.service.StorageService in project cassandra by apache.
the class BootStrapperTest method testSourceTargetComputation.
private RangeStreamer testSourceTargetComputation(String keyspaceName, int numOldNodes, int replicationFactor) throws UnknownHostException {
StorageService ss = StorageService.instance;
TokenMetadata tmd = ss.getTokenMetadata();
generateFakeEndpoints(numOldNodes);
Token myToken = tmd.partitioner.getRandomToken();
InetAddressAndPort myEndpoint = InetAddressAndPort.getByName("127.0.0.1");
assertEquals(numOldNodes, tmd.sortedTokens().size());
IFailureDetector mockFailureDetector = new IFailureDetector() {
public boolean isAlive(InetAddressAndPort ep) {
return true;
}
public void interpret(InetAddressAndPort ep) {
throw new UnsupportedOperationException();
}
public void report(InetAddressAndPort ep) {
throw new UnsupportedOperationException();
}
public void registerFailureDetectionEventListener(IFailureDetectionEventListener listener) {
throw new UnsupportedOperationException();
}
public void unregisterFailureDetectionEventListener(IFailureDetectionEventListener listener) {
throw new UnsupportedOperationException();
}
public void remove(InetAddressAndPort ep) {
throw new UnsupportedOperationException();
}
public void forceConviction(InetAddressAndPort ep) {
throw new UnsupportedOperationException();
}
};
RangeStreamer s = new RangeStreamer(tmd, null, myEndpoint, StreamOperation.BOOTSTRAP, true, DatabaseDescriptor.getEndpointSnitch(), new StreamStateStore(), mockFailureDetector, false, 1);
assertNotNull(Keyspace.open(keyspaceName));
s.addRanges(keyspaceName, Keyspace.open(keyspaceName).getReplicationStrategy().getPendingAddressRanges(tmd, myToken, myEndpoint));
Multimap<InetAddressAndPort, FetchReplica> toFetch = s.toFetch().get(keyspaceName);
// Check we get get RF new ranges in total
assertEquals(replicationFactor, toFetch.size());
// is used, they will vary.
assert toFetch.values().size() > 0;
assert toFetch.keys().stream().noneMatch(myEndpoint::equals);
return s;
}
use of org.apache.cassandra.service.StorageService in project cassandra by apache.
the class FailureDetectorTest method testConvictAfterLeft.
@Test
public void testConvictAfterLeft() throws UnknownHostException {
StorageService ss = StorageService.instance;
TokenMetadata tmd = ss.getTokenMetadata();
tmd.clearUnsafe();
IPartitioner partitioner = new RandomPartitioner();
VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);
ArrayList<Token> endpointTokens = new ArrayList<>();
ArrayList<Token> keyTokens = new ArrayList<>();
List<InetAddressAndPort> hosts = new ArrayList<>();
List<UUID> hostIds = new ArrayList<>();
// we want to convict if there is any heartbeat data present in the FD
DatabaseDescriptor.setPhiConvictThreshold(0);
// create a ring of 2 nodes
Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 3);
InetAddressAndPort leftHost = hosts.get(1);
FailureDetector.instance.report(leftHost);
// trigger handleStateLeft in StorageService
ss.onChange(leftHost, ApplicationState.STATUS_WITH_PORT, valueFactory.left(Collections.singleton(endpointTokens.get(1)), Gossiper.computeExpireTime()));
// confirm that handleStateLeft was called and leftEndpoint was removed from TokenMetadata
assertFalse("Left endpoint not removed from TokenMetadata", tmd.isMember(leftHost));
// confirm the FD's history for leftHost didn't get wiped by status jump to LEFT
FailureDetector.instance.interpret(leftHost);
assertFalse("Left endpoint not convicted", FailureDetector.instance.isAlive(leftHost));
}
use of org.apache.cassandra.service.StorageService in project eiger by wlloyd.
the class BootStrapperTest method testGuessToken.
@Test
public void testGuessToken() throws IOException {
StorageService ss = StorageService.instance;
generateFakeEndpoints(5);
InetAddress two = InetAddress.getByName("127.0.0.2");
InetAddress three = InetAddress.getByName("127.0.0.3");
InetAddress four = InetAddress.getByName("127.0.0.4");
InetAddress five = InetAddress.getByName("127.0.0.5");
Map<InetAddress, Double> load = new HashMap<InetAddress, Double>();
load.put(two, 2.0);
load.put(three, 3.0);
load.put(four, 4.0);
load.put(five, 5.0);
TokenMetadata tmd = ss.getTokenMetadata();
InetAddress source = BootStrapper.getBootstrapSource(tmd, load);
assert five.equals(source) : five + " != " + source;
InetAddress myEndpoint = InetAddress.getByName("127.0.0.1");
Range<Token> range5 = ss.getPrimaryRangeForEndpoint(five);
Token fakeToken = StorageService.getPartitioner().midpoint(range5.left, range5.right);
assert range5.contains(fakeToken);
ss.onChange(myEndpoint, ApplicationState.STATUS, StorageService.instance.valueFactory.bootstrapping(fakeToken));
tmd = ss.getTokenMetadata();
InetAddress source4 = BootStrapper.getBootstrapSource(tmd, load);
assert four.equals(source4) : four + " != " + source4;
}
Aggregations