Search in sources :

Example 6 with StorageService

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());
        });
    }
}
Also used : MessagingService(org.apache.cassandra.net.MessagingService) Arrays(java.util.Arrays) ByteBufferUtil(org.apache.cassandra.utils.ByteBufferUtil) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Gossiper(org.apache.cassandra.gms.Gossiper) InetAddress(java.net.InetAddress) SystemDistributedKeyspace(org.apache.cassandra.schema.SystemDistributedKeyspace) List(java.util.List) StorageProxy(org.apache.cassandra.service.StorageProxy) Map(java.util.Map) Cluster(org.apache.cassandra.distributed.Cluster) Pattern(java.util.regex.Pattern) Assert(org.junit.Assert) FailureDetector(org.apache.cassandra.gms.FailureDetector) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) SchemaConstants(org.apache.cassandra.schema.SchemaConstants) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) StorageProxy(org.apache.cassandra.service.StorageProxy) FailureDetector(org.apache.cassandra.gms.FailureDetector) Cluster(org.apache.cassandra.distributed.Cluster) Map(java.util.Map) InetAddress(java.net.InetAddress) StorageService(org.apache.cassandra.service.StorageService) MessagingService(org.apache.cassandra.net.MessagingService) Test(org.junit.Test)

Example 7 with StorageService

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";
        }
    });
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) ArrayList(java.util.ArrayList) Token(org.apache.cassandra.dht.Token) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) StorageService(org.apache.cassandra.service.StorageService) AbstractNetworkTopologySnitch(org.apache.cassandra.locator.AbstractNetworkTopologySnitch) UUID(java.util.UUID) BeforeClass(org.junit.BeforeClass)

Example 8 with StorageService

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;
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) FetchReplica(org.apache.cassandra.dht.RangeStreamer.FetchReplica) IFailureDetector(org.apache.cassandra.gms.IFailureDetector) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) IFailureDetectionEventListener(org.apache.cassandra.gms.IFailureDetectionEventListener) StorageService(org.apache.cassandra.service.StorageService)

Example 9 with StorageService

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));
}
Also used : RandomPartitioner(org.apache.cassandra.dht.RandomPartitioner) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) ArrayList(java.util.ArrayList) Token(org.apache.cassandra.dht.Token) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) StorageService(org.apache.cassandra.service.StorageService) UUID(java.util.UUID) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 10 with StorageService

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;
}
Also used : HashMap(java.util.HashMap) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) InetAddress(java.net.InetAddress) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test)

Aggregations

StorageService (org.apache.cassandra.service.StorageService)10 Test (org.junit.Test)6 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)5 InetAddress (java.net.InetAddress)4 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)4 HashMap (java.util.HashMap)3 UUID (java.util.UUID)3 Pattern (java.util.regex.Pattern)3 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)3 ByteBufferUtil (org.apache.cassandra.utils.ByteBufferUtil)3 BeforeClass (org.junit.BeforeClass)3 Joiner (com.google.common.base.Joiner)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Random (java.util.Random)2 Consumer (java.util.function.Consumer)2 Matcher (java.util.regex.Matcher)2 Int32Type (org.apache.cassandra.db.marshal.Int32Type)2