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);
}
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;
}
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);
}
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);
}
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");
}
}
Aggregations