Search in sources :

Example 1 with StorageService

use of org.apache.cassandra.service.StorageService in project cassandra by apache.

the class RangeTombstoneListTest method testSetInitialAllocationSize.

@Test
public void testSetInitialAllocationSize() {
    int original = DatabaseDescriptor.getInitialRangeTombstoneListAllocationSize();
    final StorageService storageService = StorageService.instance;
    final Consumer<Throwable> expectIllegalStateExceptio = exception -> {
        assertSame(String.format("The actual exception message:<%s>", exception.getMessage()), IllegalStateException.class, exception.getClass());
        assertEquals("Not updating initial_range_tombstone_allocation_size as it must be in the range [0, 1024] inclusive", exception.getMessage());
    };
    try {
        // prevent bad ones
        assertHasException(() -> storageService.setInitialRangeTombstoneListAllocationSize(-1), expectIllegalStateExceptio);
        assertHasException(() -> storageService.setInitialRangeTombstoneListAllocationSize(1025), expectIllegalStateExceptio);
        // accept good ones
        storageService.setInitialRangeTombstoneListAllocationSize(1);
        storageService.setInitialRangeTombstoneListAllocationSize(1024);
    } finally {
        storageService.setInitialRangeTombstoneListAllocationSize(original);
    }
}
Also used : Iterator(java.util.Iterator) BeforeClass(org.junit.BeforeClass) ByteBufferUtil(org.apache.cassandra.utils.ByteBufferUtil) StorageService(org.apache.cassandra.service.StorageService) Assert.assertTrue(org.junit.Assert.assertTrue) Random(java.util.Random) Test(org.junit.Test) Global.nanoTime(org.apache.cassandra.utils.Clock.Global.nanoTime) ByteBuffer(java.nio.ByteBuffer) Consumer(java.util.function.Consumer) Assert.assertSame(org.junit.Assert.assertSame) Int32Type(org.apache.cassandra.db.marshal.Int32Type) Matcher(java.util.regex.Matcher) ThrowingRunnable(org.apache.cassandra.distributed.shared.ThrowingRunnable) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.fail(org.junit.Assert.fail) Pattern(java.util.regex.Pattern) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Assert.assertEquals(org.junit.Assert.assertEquals) Joiner(com.google.common.base.Joiner) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test)

Example 2 with StorageService

use of org.apache.cassandra.service.StorageService in project cassandra by apache.

the class GossipHelper method changeGossipState.

/**
 * Changes gossip state of the `peer` on `target`
 */
public static void changeGossipState(IInvokableInstance target, IInstance peer, List<VersionedApplicationState> newState) {
    InetSocketAddress addr = peer.broadcastAddress();
    UUID hostId = peer.config().hostId();
    int netVersion = peer.getMessagingVersion();
    target.runOnInstance(() -> {
        InetAddressAndPort endpoint = toCassandraInetAddressAndPort(addr);
        StorageService storageService = StorageService.instance;
        Gossiper.runInGossipStageBlocking(() -> {
            EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
            if (state == null) {
                Gossiper.instance.initializeNodeUnsafe(endpoint, hostId, netVersion, 1);
                state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
                if (state.isAlive() && !Gossiper.instance.isDeadState(state))
                    Gossiper.instance.realMarkAlive(endpoint, state);
            }
            for (VersionedApplicationState value : newState) {
                ApplicationState as = toApplicationState(value);
                VersionedValue vv = toVersionedValue(value);
                state.addApplicationState(as, vv);
                storageService.onChange(endpoint, as, vv);
            }
        });
    });
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) VersionedValue(org.apache.cassandra.gms.VersionedValue) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) DistributedTestSnitch.toCassandraInetAddressAndPort(org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort) InetSocketAddress(java.net.InetSocketAddress) VersionedApplicationState(org.apache.cassandra.distributed.shared.VersionedApplicationState) VersionedApplicationState(org.apache.cassandra.distributed.shared.VersionedApplicationState) ApplicationState(org.apache.cassandra.gms.ApplicationState) UUID(java.util.UUID) StorageService(org.apache.cassandra.service.StorageService)

Example 3 with StorageService

use of org.apache.cassandra.service.StorageService in project eiger by wlloyd.

the class BootStrapperTest method testMulitipleAutomaticBootstraps.

@Test
public void testMulitipleAutomaticBootstraps() throws IOException {
    StorageService ss = StorageService.instance;
    generateFakeEndpoints(5);
    InetAddress[] addrs = new InetAddress[] { InetAddress.getByName("127.0.0.2"), InetAddress.getByName("127.0.0.3"), InetAddress.getByName("127.0.0.4"), InetAddress.getByName("127.0.0.5") };
    InetAddress[] bootstrapAddrs = new InetAddress[] { InetAddress.getByName("127.0.0.12"), InetAddress.getByName("127.0.0.13"), InetAddress.getByName("127.0.0.14"), InetAddress.getByName("127.0.0.15") };
    Map<InetAddress, Double> load = new HashMap<InetAddress, Double>();
    for (int i = 0; i < addrs.length; i++) load.put(addrs[i], (double) i + 2);
    // give every node a bootstrap source.
    for (int i = 3; i >= 0; i--) {
        InetAddress bootstrapSource = BootStrapper.getBootstrapSource(ss.getTokenMetadata(), load);
        assert bootstrapSource != null;
        assert bootstrapSource.equals(addrs[i]) : String.format("expected %s but got %s for %d", addrs[i], bootstrapSource, i);
        assert !ss.getTokenMetadata().getBootstrapTokens().containsValue(bootstrapSource);
        Range<Token> range = ss.getPrimaryRangeForEndpoint(bootstrapSource);
        Token token = StorageService.getPartitioner().midpoint(range.left, range.right);
        assert range.contains(token);
        ss.onChange(bootstrapAddrs[i], ApplicationState.STATUS, StorageService.instance.valueFactory.bootstrapping(token));
    }
    // any further attempt to bootsrtap should fail since every node in the cluster is splitting.
    try {
        BootStrapper.getBootstrapSource(ss.getTokenMetadata(), load);
        throw new AssertionError("This bootstrap should have failed.");
    } catch (RuntimeException ex) {
    // success!
    }
    // indicate that one of the nodes is done. see if the node it was bootstrapping from is still available.
    Range<Token> range = ss.getPrimaryRangeForEndpoint(addrs[2]);
    Token token = StorageService.getPartitioner().midpoint(range.left, range.right);
    ss.onChange(bootstrapAddrs[2], ApplicationState.STATUS, StorageService.instance.valueFactory.normal(token));
    load.put(bootstrapAddrs[2], 0d);
    InetAddress addr = BootStrapper.getBootstrapSource(ss.getTokenMetadata(), load);
    assert addr != null && addr.equals(addrs[2]);
}
Also used : HashMap(java.util.HashMap) InetAddress(java.net.InetAddress) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test)

Example 4 with StorageService

use of org.apache.cassandra.service.StorageService in project eiger by wlloyd.

the class BootStrapperTest method testSourceTargetComputation.

private void testSourceTargetComputation(String table, int numOldNodes, int replicationFactor) throws UnknownHostException {
    StorageService ss = StorageService.instance;
    generateFakeEndpoints(numOldNodes);
    Token myToken = StorageService.getPartitioner().getRandomToken();
    InetAddress myEndpoint = InetAddress.getByName("127.0.0.1");
    TokenMetadata tmd = ss.getTokenMetadata();
    assertEquals(numOldNodes, tmd.sortedTokens().size());
    BootStrapper b = new BootStrapper(myEndpoint, myToken, tmd);
    Multimap<Range<Token>, InetAddress> res = b.getRangesWithSources(table);
    int transferCount = 0;
    for (Map.Entry<Range<Token>, Collection<InetAddress>> e : res.asMap().entrySet()) {
        assert e.getValue() != null && e.getValue().size() > 0 : StringUtils.join(e.getValue(), ", ");
        transferCount++;
    }
    assertEquals(replicationFactor, transferCount);
    IFailureDetector mockFailureDetector = new IFailureDetector() {

        public boolean isAlive(InetAddress ep) {
            return true;
        }

        public void interpret(InetAddress ep) {
            throw new UnsupportedOperationException();
        }

        public void report(InetAddress ep) {
            throw new UnsupportedOperationException();
        }

        public void registerFailureDetectionEventListener(IFailureDetectionEventListener listener) {
            throw new UnsupportedOperationException();
        }

        public void unregisterFailureDetectionEventListener(IFailureDetectionEventListener listener) {
            throw new UnsupportedOperationException();
        }

        public void remove(InetAddress ep) {
            throw new UnsupportedOperationException();
        }

        public void clear(InetAddress ep) {
            throw new UnsupportedOperationException();
        }
    };
    Multimap<InetAddress, Range<Token>> temp = BootStrapper.getWorkMap(res, mockFailureDetector);
    // is used, they will vary.
    assert temp.keySet().size() > 0;
    assert temp.asMap().values().iterator().next().size() > 0;
    assert !temp.keySet().iterator().next().equals(myEndpoint);
}
Also used : TokenMetadata(org.apache.cassandra.locator.TokenMetadata) StorageService(org.apache.cassandra.service.StorageService) IFailureDetector(org.apache.cassandra.gms.IFailureDetector) Collection(java.util.Collection) IFailureDetectionEventListener(org.apache.cassandra.gms.IFailureDetectionEventListener) InetAddress(java.net.InetAddress) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with StorageService

use of org.apache.cassandra.service.StorageService in project cassandra by apache.

the class RangeTombstoneListTest method testSetResizeFactor.

@Test
public void testSetResizeFactor() {
    double original = DatabaseDescriptor.getRangeTombstoneListGrowthFactor();
    final StorageService storageService = StorageService.instance;
    final Consumer<Throwable> expectIllegalStateExceptio = exception -> {
        assertSame(IllegalStateException.class, exception.getClass());
        assertEquals("Not updating range_tombstone_resize_factor as growth factor must be in the range [1.2, 5.0] inclusive", exception.getMessage());
    };
    try {
        // prevent bad ones
        assertHasException(() -> storageService.setRangeTombstoneListResizeGrowthFactor(-1), expectIllegalStateExceptio);
        assertHasException(() -> storageService.setRangeTombstoneListResizeGrowthFactor(0), expectIllegalStateExceptio);
        assertHasException(() -> storageService.setRangeTombstoneListResizeGrowthFactor(1.1), expectIllegalStateExceptio);
        assertHasException(() -> storageService.setRangeTombstoneListResizeGrowthFactor(5.1), expectIllegalStateExceptio);
        // accept good ones
        storageService.setRangeTombstoneListResizeGrowthFactor(1.2);
        storageService.setRangeTombstoneListResizeGrowthFactor(2.0);
        storageService.setRangeTombstoneListResizeGrowthFactor(5.0);
    } finally {
        storageService.setRangeTombstoneListResizeGrowthFactor(original);
    }
}
Also used : Iterator(java.util.Iterator) BeforeClass(org.junit.BeforeClass) ByteBufferUtil(org.apache.cassandra.utils.ByteBufferUtil) StorageService(org.apache.cassandra.service.StorageService) Assert.assertTrue(org.junit.Assert.assertTrue) Random(java.util.Random) Test(org.junit.Test) Global.nanoTime(org.apache.cassandra.utils.Clock.Global.nanoTime) ByteBuffer(java.nio.ByteBuffer) Consumer(java.util.function.Consumer) Assert.assertSame(org.junit.Assert.assertSame) Int32Type(org.apache.cassandra.db.marshal.Int32Type) Matcher(java.util.regex.Matcher) ThrowingRunnable(org.apache.cassandra.distributed.shared.ThrowingRunnable) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.fail(org.junit.Assert.fail) Pattern(java.util.regex.Pattern) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Assert.assertEquals(org.junit.Assert.assertEquals) Joiner(com.google.common.base.Joiner) 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