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