Search in sources :

Example 16 with IPartitioner

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

the class SystemTable method removeToken.

/**
     * Remove stored token being used by another node
     */
public static synchronized void removeToken(Token token) {
    IPartitioner p = StorageService.getPartitioner();
    RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, RING_KEY);
    rm.delete(new QueryPath(STATUS_CF, null, p.getTokenFactory().toByteArray(token)), LamportClock.getVersion());
    try {
        rm.apply();
    } catch (IOException e) {
        throw new IOError(e);
    }
    forceBlockingFlush(STATUS_CF);
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) IOError(java.io.IOError) IOException(java.io.IOException) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 17 with IPartitioner

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

the class SystemTable method loadTokens.

/**
     * Return a map of stored tokens to IP addresses
     *
     */
public static HashMap<Token, InetAddress> loadTokens() {
    HashMap<Token, InetAddress> tokenMap = new HashMap<Token, InetAddress>();
    IPartitioner p = StorageService.getPartitioner();
    Table table = Table.open(Table.SYSTEM_TABLE);
    QueryFilter filter = QueryFilter.getIdentityFilter(decorate(RING_KEY), new QueryPath(STATUS_CF));
    ColumnFamily cf = ColumnFamilyStore.removeDeleted(table.getColumnFamilyStore(STATUS_CF).getColumnFamily(filter), Integer.MAX_VALUE);
    if (cf != null) {
        for (IColumn column : cf.getSortedColumns()) {
            try {
                ByteBuffer v = column.value();
                byte[] addr = new byte[v.remaining()];
                ByteBufferUtil.arrayCopy(v, v.position(), addr, 0, v.remaining());
                tokenMap.put(p.getTokenFactory().fromByteArray(column.name()), InetAddress.getByAddress(addr));
            } catch (UnknownHostException e) {
                throw new IOError(e);
            }
        }
    }
    return tokenMap;
}
Also used : UnknownHostException(java.net.UnknownHostException) Token(org.apache.cassandra.dht.Token) ByteBuffer(java.nio.ByteBuffer) QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IOError(java.io.IOError) InetAddress(java.net.InetAddress) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 18 with IPartitioner

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

the class SystemTable method updateToken.

/**
     * This method is used to update the System Table with the new token for this node
    */
public static synchronized void updateToken(Token token) {
    IPartitioner p = StorageService.getPartitioner();
    ColumnFamily cf = ColumnFamily.create(Table.SYSTEM_TABLE, STATUS_CF);
    cf.addColumn(new Column(SystemTable.TOKEN, p.getTokenFactory().toByteArray(token), LamportClock.getVersion()));
    RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCATION_KEY);
    rm.add(cf);
    try {
        rm.apply();
    } catch (IOException e) {
        throw new IOError(e);
    }
    forceBlockingFlush(STATUS_CF);
}
Also used : IOError(java.io.IOError) IOException(java.io.IOException) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 19 with IPartitioner

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

the class SystemTable method updateToken.

/**
     * Record token being used by another node
     */
public static synchronized void updateToken(InetAddress ep, Token token) {
    if (ep == FBUtilities.getLocalAddress())
        return;
    IPartitioner p = StorageService.getPartitioner();
    ColumnFamily cf = ColumnFamily.create(Table.SYSTEM_TABLE, STATUS_CF);
    cf.addColumn(new Column(p.getTokenFactory().toByteArray(token), ByteBuffer.wrap(ep.getAddress()), LamportClock.getVersion()));
    RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, RING_KEY);
    rm.add(cf);
    try {
        rm.apply();
    } catch (IOException e) {
        throw new IOError(e);
    }
    forceBlockingFlush(STATUS_CF);
}
Also used : IOError(java.io.IOError) IOException(java.io.IOException) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 20 with IPartitioner

use of org.apache.cassandra.dht.IPartitioner 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)

Aggregations

IPartitioner (org.apache.cassandra.dht.IPartitioner)53 Token (org.apache.cassandra.dht.Token)27 Test (org.junit.Test)27 InetAddress (java.net.InetAddress)15 Range (org.apache.cassandra.dht.Range)14 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)10 IdentityQueryFilter (org.apache.cassandra.db.columniterator.IdentityQueryFilter)9 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)9 VersionedValue (org.apache.cassandra.gms.VersionedValue)9 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 RandomPartitioner (org.apache.cassandra.dht.RandomPartitioner)6 IOError (java.io.IOError)4 ByteBuffer (java.nio.ByteBuffer)4 IFilter (org.apache.cassandra.db.filter.IFilter)3 QueryPath (org.apache.cassandra.db.filter.QueryPath)3 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)3 IndexExpression (org.apache.cassandra.thrift.IndexExpression)3 HashMultimap (com.google.common.collect.HashMultimap)2 Multimap (com.google.common.collect.Multimap)2