Package org.apache.cassandra.service

Examples of org.apache.cassandra.service.StorageService$BootstrapInitiateDoneVerbHandler


   * @param args
   */
  public static void main(String[] args) throws Throwable
  {
    LogUtil.init();
        StorageService s = StorageService.instance();
        s.start();
    Loader loader = new Loader(s);
    loader.load("mbox_importer.xml");
  }
View Full Code Here


        return map;
    }

    public static void main(String[] args) throws Throwable
    {
        StorageService ss = StorageService.instance();
        ss.updateTokenMetadata(BigInteger.valueOf(3), new EndPoint("A", 7000));
        ss.updateTokenMetadata(BigInteger.valueOf(6), new EndPoint("B", 7000));
        ss.updateTokenMetadata(BigInteger.valueOf(9), new EndPoint("C", 7000));
        ss.updateTokenMetadata(BigInteger.valueOf(12), new EndPoint("D", 7000));
        ss.updateTokenMetadata(BigInteger.valueOf(15), new EndPoint("E", 7000));
        ss.updateTokenMetadata(BigInteger.valueOf(18), new EndPoint("F", 7000));
        ss.updateTokenMetadata(BigInteger.valueOf(21), new EndPoint("G", 7000));
        ss.updateTokenMetadata(BigInteger.valueOf(24), new EndPoint("H", 7000));
       
        Runnable runnable = new LeaveJoinProtocolImpl( new EndPoint[]{new EndPoint("C", 7000), new EndPoint("D", 7000)}, new BigInteger[]{BigInteger.valueOf(22), BigInteger.valueOf(23)} );
        runnable.run();
    }
View Full Code Here

            System.out.println("Usage : java com.facebook.infrastructure.tools.KeyChecker <file containing all keys>");
            System.exit(1);
        }
       
        LogUtil.init();
        StorageService s = StorageService.instance();
        s.start();
       
        /* Sleep for proper discovery */
        Thread.sleep(240000);
        /* Create the file for the missing keys */
        RandomAccessFile raf = new RandomAccessFile( "Missing-" + FBUtilities.getHostName() + ".dat", "rw");
View Full Code Here

    public static class BootstrapTokenVerbHandler implements IVerbHandler
    {
        public void doVerb(Message message, String id)
        {
            StorageService ss = StorageService.instance;
            String tokenString = StorageService.getPartitioner().getTokenFactory().toString(ss.getBootstrapToken());
            Message response = message.getInternalReply(tokenString.getBytes(Charsets.UTF_8));
            MessagingService.instance().sendReply(response, id, message.getFrom());
        }
View Full Code Here

    }
   
    @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]);
    }
View Full Code Here

    }

    @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;
    }
View Full Code Here

        }
    }

    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());
        RangeStreamer s = new RangeStreamer(tmd, myEndpoint, OperationType.BOOTSTRAP);
        IFailureDetector mockFailureDetector = new IFailureDetector()
        {
            public boolean isAlive(InetAddress ep)
View Full Code Here

    public static class BootstrapTokenVerbHandler implements IVerbHandler
    {
        public void doVerb(Message message, String id)
        {
            StorageService ss = StorageService.instance;
            String tokenString = StorageService.getPartitioner().getTokenFactory().toString(ss.getBootstrapToken());
            Message response = message.getInternalReply(tokenString.getBytes(Charsets.UTF_8), message.getVersion());
            MessagingService.instance().sendReply(response, id, message.getFrom());
        }
View Full Code Here

public class BootStrapperTest
{
    @Test
    public void testGuessToken() throws IOException
    {
        StorageService ss = StorageService.instance();

        generateFakeEndpoints(3);

        InetAddress one = InetAddress.getByName("127.0.0.2");
        InetAddress two = InetAddress.getByName("127.0.0.3");
        InetAddress three = InetAddress.getByName("127.0.0.4");
        Map<InetAddress, Double> load = new HashMap<InetAddress, Double>();
        load.put(one, 1.0);
        load.put(two, 2.0);
        load.put(three, 3.0);

        TokenMetadata tmd = ss.getTokenMetadata();
        InetAddress source = BootStrapper.getBootstrapSource(tmd, load);
        assert three.equals(source);

        InetAddress myEndpoint = InetAddress.getByName("127.0.0.1");
        Range range3 = ss.getPrimaryRangeForEndPoint(three);
        Token fakeToken = ((IPartitioner)StorageService.getPartitioner()).midpoint(range3.left, range3.right);
        assert range3.contains(fakeToken);
        ss.onChange(myEndpoint, StorageService.MOVE_STATE, new ApplicationState(StorageService.STATE_BOOTSTRAPPING + StorageService.Delimiter + ss.getPartitioner().getTokenFactory().toString(fakeToken)));
        tmd = ss.getTokenMetadata();

        InetAddress source2 = BootStrapper.getBootstrapSource(tmd, load);
        assert two.equals(source2) : source2;
    }
View Full Code Here

        testSourceTargetComputation(100);
    }

    private void testSourceTargetComputation(int numOldNodes) 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(ss.getReplicationStrategy(), myEndpoint, myToken, tmd);
        Multimap<Range, InetAddress> res = b.getRangesWithSources();
       
        int transferCount = 0;
        for (Map.Entry<Range, Collection<InetAddress>> e : res.asMap().entrySet())
        {
View Full Code Here

TOP

Related Classes of org.apache.cassandra.service.StorageService$BootstrapInitiateDoneVerbHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.