Search in sources :

Example 1 with RandomPartitioner

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

the class IndexSummaryTest method testAddEmptyKey.

@Test
public void testAddEmptyKey() throws Exception {
    IPartitioner p = new RandomPartitioner();
    try (IndexSummaryBuilder builder = new IndexSummaryBuilder(1, 1, BASE_SAMPLING_LEVEL)) {
        builder.maybeAddEntry(p.decorateKey(ByteBufferUtil.EMPTY_BYTE_BUFFER), 0);
        IndexSummary summary = builder.build(p);
        assertEquals(1, summary.size());
        assertEquals(0, summary.getPosition(0));
        assertArrayEquals(new byte[0], summary.getKey(0));
        DataOutputBuffer dos = new DataOutputBuffer();
        IndexSummary.serializer.serialize(summary, dos);
        DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dos.toByteArray()));
        IndexSummary loaded = IndexSummary.serializer.deserialize(dis, p, 1, 1);
        assertEquals(1, loaded.size());
        assertEquals(summary.getPosition(0), loaded.getPosition(0));
        assertArrayEquals(summary.getKey(0), summary.getKey(0));
        summary.close();
        loaded.close();
    }
}
Also used : RandomPartitioner(org.apache.cassandra.dht.RandomPartitioner) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) DataInputStream(java.io.DataInputStream) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 2 with RandomPartitioner

use of org.apache.cassandra.dht.RandomPartitioner in project eiger by wlloyd.

the class ThriftValidation method validateKeyRange.

public static void validateKeyRange(CFMetaData metadata, ByteBuffer superColumn, KeyRange range) throws InvalidRequestException {
    if ((range.start_key == null) != (range.end_key == null)) {
        throw new InvalidRequestException("start key and end key must either both be non-null, or both be null");
    }
    if ((range.start_token == null) != (range.end_token == null)) {
        throw new InvalidRequestException("start token and end token must either both be non-null, or both be null");
    }
    if ((range.start_key == null) == (range.start_token == null)) {
        throw new InvalidRequestException("exactly one of {start key, end key} or {start token, end token} must be specified");
    }
    if (range.start_key != null) {
        IPartitioner p = StorageService.getPartitioner();
        Token startToken = p.getToken(range.start_key);
        Token endToken = p.getToken(range.end_key);
        if (startToken.compareTo(endToken) > 0 && !endToken.isMinimum(p)) {
            if (p instanceof RandomPartitioner)
                throw new InvalidRequestException("start key's md5 sorts after end key's md5.  this is not allowed; you probably should not specify end key at all, under RandomPartitioner");
            else
                throw new InvalidRequestException("start key must sort before (or equal to) finish key in your partitioner!");
        }
    }
    validateFilterClauses(metadata, range.row_filter);
    if (!isEmpty(range.row_filter) && superColumn != null) {
        throw new InvalidRequestException("super columns are not yet supported for indexing");
    }
    if (!isEmpty(range.row_filter) && range.start_key == null) {
        // See KeySearcher.search()
        throw new InvalidRequestException("filtered queries must use concrete keys rather than tokens");
    }
    if (range.count <= 0) {
        throw new InvalidRequestException("maxRows must be positive");
    }
}
Also used : RandomPartitioner(org.apache.cassandra.dht.RandomPartitioner) Token(org.apache.cassandra.dht.Token) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 3 with RandomPartitioner

use of org.apache.cassandra.dht.RandomPartitioner in project eiger by wlloyd.

the class MerkleTreeTest method clear.

@Before
public void clear() {
    TOKEN_SCALE = new BigInteger("8");
    partitioner = new RandomPartitioner();
    mt = new MerkleTree(partitioner, fullRange(), RECOMMENDED_DEPTH, Integer.MAX_VALUE);
}
Also used : RandomPartitioner(org.apache.cassandra.dht.RandomPartitioner) BigInteger(java.math.BigInteger) Before(org.junit.Before)

Example 4 with RandomPartitioner

use of org.apache.cassandra.dht.RandomPartitioner 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<InetAddress> 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);
    InetAddress leftHost = hosts.get(1);
    FailureDetector.instance.report(leftHost);
    // trigger handleStateLeft in StorageService
    ss.onChange(leftHost, ApplicationState.STATUS, 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) 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) InetAddress(java.net.InetAddress) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 5 with RandomPartitioner

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

the class PropertyFileSnitchTest method setup.

@Before
public void setup() throws ConfigurationException, IOException {
    String confFile = FBUtilities.resourceToFile(PropertyFileSnitch.SNITCH_PROPERTIES_FILENAME);
    effectiveFile = Paths.get(confFile);
    backupFile = Paths.get(confFile + ".bak");
    restoreOrigConfigFile();
    InetAddress[] hosts = { // this exists in the config file
    InetAddress.getByName("127.0.0.1"), // this exists in the config file
    InetAddress.getByName("127.0.0.2"), // this does not exist in the config file
    InetAddress.getByName("127.0.0.9") };
    IPartitioner partitioner = new RandomPartitioner();
    valueFactory = new VersionedValue.VersionedValueFactory(partitioner);
    tokenMap = new HashMap<>();
    for (InetAddress host : hosts) {
        Set<Token> tokens = Collections.singleton(partitioner.getRandomToken());
        Gossiper.instance.initializeNodeUnsafe(host, UUID.randomUUID(), 1);
        Gossiper.instance.injectApplicationState(host, ApplicationState.TOKENS, valueFactory.tokens(tokens));
        setNodeShutdown(host);
        tokenMap.put(host, tokens);
    }
}
Also used : RandomPartitioner(org.apache.cassandra.dht.RandomPartitioner) VersionedValue(org.apache.cassandra.gms.VersionedValue) Token(org.apache.cassandra.dht.Token) InetAddress(java.net.InetAddress) IPartitioner(org.apache.cassandra.dht.IPartitioner) Before(org.junit.Before)

Aggregations

RandomPartitioner (org.apache.cassandra.dht.RandomPartitioner)8 IPartitioner (org.apache.cassandra.dht.IPartitioner)6 Token (org.apache.cassandra.dht.Token)4 Before (org.junit.Before)3 InetAddress (java.net.InetAddress)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 ByteBuffer (java.nio.ByteBuffer)1 UUID (java.util.UUID)1 TimeoutException (java.util.concurrent.TimeoutException)1 AbstractBounds (org.apache.cassandra.dht.AbstractBounds)1 Bounds (org.apache.cassandra.dht.Bounds)1 VersionedValue (org.apache.cassandra.gms.VersionedValue)1 DataOutputBuffer (org.apache.cassandra.io.util.DataOutputBuffer)1 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)1