Search in sources :

Example 26 with BigIntegerToken

use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.

the class RangeTest method testIntersectionTwoWraps.

@Test
public void testIntersectionTwoWraps() {
    Range<Token> wraps1 = new Range<Token>(new BigIntegerToken("100"), new BigIntegerToken("20"));
    Range<Token> wraps2 = new Range<Token>(new BigIntegerToken("120"), new BigIntegerToken("90"));
    Range<Token> wraps3 = new Range<Token>(new BigIntegerToken("120"), new BigIntegerToken("110"));
    Range<Token> wraps4 = new Range<Token>(new BigIntegerToken("10"), new BigIntegerToken("0"));
    Range<Token> wraps5 = new Range<Token>(new BigIntegerToken("10"), new BigIntegerToken("1"));
    Range<Token> wraps6 = new Range<Token>(new BigIntegerToken("30"), new BigIntegerToken("10"));
    assertIntersection(wraps1, wraps2, new Range<Token>(new BigIntegerToken("120"), new BigIntegerToken("20")));
    assertIntersection(wraps1, wraps3, new Range<Token>(new BigIntegerToken("120"), new BigIntegerToken("20")), new Range<Token>(new BigIntegerToken("100"), new BigIntegerToken("110")));
    assertIntersection(wraps1, wraps4, new Range<Token>(new BigIntegerToken("10"), new BigIntegerToken("20")), new Range<Token>(new BigIntegerToken("100"), new BigIntegerToken("0")));
    assertIntersection(wraps1, wraps5, new Range<Token>(new BigIntegerToken("10"), new BigIntegerToken("20")), new Range<Token>(new BigIntegerToken("100"), new BigIntegerToken("1")));
    assertIntersection(wraps1, wraps6, new Range<Token>(new BigIntegerToken("100"), new BigIntegerToken("10")));
}
Also used : BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) Test(org.junit.Test)

Example 27 with BigIntegerToken

use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.

the class PendingRangeMapsTest method testWrapAroundRanges.

@Test
public void testWrapAroundRanges() throws UnknownHostException {
    PendingRangeMaps pendingRangeMaps = new PendingRangeMaps();
    pendingRangeMaps.addPendingRange(genRange("5", "15"), InetAddress.getByName("127.0.0.1"));
    pendingRangeMaps.addPendingRange(genRange("15", "25"), InetAddress.getByName("127.0.0.2"));
    pendingRangeMaps.addPendingRange(genRange("25", "35"), InetAddress.getByName("127.0.0.3"));
    pendingRangeMaps.addPendingRange(genRange("35", "45"), InetAddress.getByName("127.0.0.4"));
    pendingRangeMaps.addPendingRange(genRange("45", "55"), InetAddress.getByName("127.0.0.5"));
    pendingRangeMaps.addPendingRange(genRange("45", "65"), InetAddress.getByName("127.0.0.6"));
    pendingRangeMaps.addPendingRange(genRange("65", "7"), InetAddress.getByName("127.0.0.7"));
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("0")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("5")).size());
    assertEquals(2, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("7")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("10")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("15")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("20")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("25")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("35")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("45")).size());
    assertEquals(2, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("55")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("65")).size());
    Collection<InetAddress> endpoints = pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("6"));
    assertTrue(endpoints.contains(InetAddress.getByName("127.0.0.1")));
    assertTrue(endpoints.contains(InetAddress.getByName("127.0.0.7")));
}
Also used : BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 28 with BigIntegerToken

use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.

the class PendingRangeMapsTest method testPendingEndpoints.

@Test
public void testPendingEndpoints() throws UnknownHostException {
    PendingRangeMaps pendingRangeMaps = new PendingRangeMaps();
    pendingRangeMaps.addPendingRange(genRange("5", "15"), InetAddress.getByName("127.0.0.1"));
    pendingRangeMaps.addPendingRange(genRange("15", "25"), InetAddress.getByName("127.0.0.2"));
    pendingRangeMaps.addPendingRange(genRange("25", "35"), InetAddress.getByName("127.0.0.3"));
    pendingRangeMaps.addPendingRange(genRange("35", "45"), InetAddress.getByName("127.0.0.4"));
    pendingRangeMaps.addPendingRange(genRange("45", "55"), InetAddress.getByName("127.0.0.5"));
    pendingRangeMaps.addPendingRange(genRange("45", "65"), InetAddress.getByName("127.0.0.6"));
    assertEquals(0, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("0")).size());
    assertEquals(0, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("5")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("10")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("15")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("20")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("25")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("35")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("45")).size());
    assertEquals(2, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("55")).size());
    assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("65")).size());
    Collection<InetAddress> endpoints = pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("15"));
    assertTrue(endpoints.contains(InetAddress.getByName("127.0.0.1")));
}
Also used : BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 29 with BigIntegerToken

use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.

the class OldNetworkTopologyStrategyTest method testMoveBeforePreviousNeighbor.

@SuppressWarnings("unchecked")
@Test
public void testMoveBeforePreviousNeighbor() throws UnknownHostException {
    // moves before its previous neighbor in the ring
    int movingNodeIdx = 1;
    int movingNodeIdxAfterMove = 7;
    BigIntegerToken newToken = new BigIntegerToken("158873535527910577765226390751398592512");
    BigIntegerToken[] tokens = initTokens();
    BigIntegerToken[] tokensAfterMove = initTokensAfterMove(tokens, movingNodeIdx, newToken);
    Pair<Set<Range<Token>>, Set<Range<Token>>> ranges = calculateStreamAndFetchRanges(tokens, tokensAfterMove, movingNodeIdx);
    Range<Token>[] toStream = ranges.left.toArray(new Range[0]);
    Range<Token>[] toFetch = ranges.right.toArray(new Range[0]);
    Arrays.sort(toStream);
    Arrays.sort(toFetch);
    Range<Token>[] toStreamExpected = new Range[2];
    toStreamExpected[0] = new Range<Token>(getToken(movingNodeIdx, tokensAfterMove), getToken(movingNodeIdx - 1, tokensAfterMove));
    toStreamExpected[1] = new Range<Token>(getToken(movingNodeIdx - 1, tokens), getToken(movingNodeIdx, tokens));
    Arrays.sort(toStreamExpected);
    Range<Token>[] toFetchExpected = new Range[1];
    toFetchExpected[0] = new Range<Token>(getToken(movingNodeIdxAfterMove - 1, tokens), getToken(movingNodeIdxAfterMove, tokens));
    Arrays.sort(toFetchExpected);
    System.out.println("toStream : " + Arrays.toString(toStream));
    System.out.println("toFetch : " + Arrays.toString(toFetch));
    System.out.println("toStreamExpected : " + Arrays.toString(toStreamExpected));
    System.out.println("toFetchExpected : " + Arrays.toString(toFetchExpected));
    assertEquals(Arrays.equals(toStream, toStreamExpected), true);
    assertEquals(Arrays.equals(toFetch, toFetchExpected), true);
}
Also used : Set(java.util.Set) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) Test(org.junit.Test)

Example 30 with BigIntegerToken

use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.

the class OldNetworkTopologyStrategyTest method calculateStreamAndFetchRanges.

private Pair<Set<Range<Token>>, Set<Range<Token>>> calculateStreamAndFetchRanges(BigIntegerToken[] tokens, BigIntegerToken[] tokensAfterMove, int movingNodeIdx) throws UnknownHostException {
    RackInferringSnitch endpointSnitch = new RackInferringSnitch();
    InetAddress movingNode = InetAddress.getByName("254.0.0." + Integer.toString(movingNodeIdx + 1));
    TokenMetadata tokenMetadataCurrent = initTokenMetadata(tokens);
    TokenMetadata tokenMetadataAfterMove = initTokenMetadata(tokensAfterMove);
    AbstractReplicationStrategy strategy = new OldNetworkTopologyStrategy("Keyspace1", tokenMetadataCurrent, endpointSnitch, optsWithRF(2));
    Collection<Range<Token>> currentRanges = strategy.getAddressRanges().get(movingNode);
    Collection<Range<Token>> updatedRanges = strategy.getPendingAddressRanges(tokenMetadataAfterMove, tokensAfterMove[movingNodeIdx], movingNode);
    Pair<Set<Range<Token>>, Set<Range<Token>>> ranges = StorageService.instance.calculateStreamAndFetchRanges(currentRanges, updatedRanges);
    return ranges;
}
Also used : Set(java.util.Set) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) InetAddress(java.net.InetAddress)

Aggregations

BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)31 Test (org.junit.Test)24 Token (org.apache.cassandra.dht.Token)12 InetAddress (java.net.InetAddress)11 BytesToken (org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken)11 Set (java.util.Set)6 Range (org.apache.cassandra.dht.Range)5 VersionedValue (org.apache.cassandra.gms.VersionedValue)4 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)4 HashMultimap (com.google.common.collect.HashMultimap)2 Multimap (com.google.common.collect.Multimap)2 ArrayList (java.util.ArrayList)2 IPartitioner (org.apache.cassandra.dht.IPartitioner)2 StringToken (org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)2 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)2