use of org.apache.cassandra.dht.IPartitioner in project eiger by wlloyd.
the class StreamingTransferTest method testTransferTable.
@Test
public void testTransferTable() throws Exception {
final Table table = Table.open("Keyspace1");
final ColumnFamilyStore cfs = table.getColumnFamilyStore("Indexed1");
List<String> keys = createAndTransfer(table, cfs, new Mutator() {
public void mutate(String key, String col, long timestamp) throws Exception {
long val = key.hashCode();
RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes(key));
ColumnFamily cf = ColumnFamily.create(table.name, cfs.columnFamily);
cf.addColumn(column(col, "v", timestamp));
cf.addColumn(new Column(ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(val), timestamp));
rm.add(cf);
logger.debug("Applying row to transfer " + rm);
rm.apply();
}
});
// confirm that the secondary index was recovered
for (String key : keys) {
long val = key.hashCode();
IPartitioner p = StorageService.getPartitioner();
IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(val));
List<IndexExpression> clause = Arrays.asList(expr);
IFilter filter = new IdentityQueryFilter();
Range<RowPosition> range = Util.range("", "");
List<Row> rows = cfs.search(clause, range, 100, filter);
assertEquals(1, rows.size());
assert rows.get(0).key.key.equals(ByteBufferUtil.bytes(key));
}
}
use of org.apache.cassandra.dht.IPartitioner in project eiger by wlloyd.
the class StreamingTransferTest method transfer.
private void transfer(Table table, SSTableReader sstable) throws Exception {
IPartitioner p = StorageService.getPartitioner();
List<Range<Token>> ranges = new ArrayList<Range<Token>>();
ranges.add(new Range<Token>(p.getMinimumToken(), p.getToken(ByteBufferUtil.bytes("key1"))));
ranges.add(new Range<Token>(p.getToken(ByteBufferUtil.bytes("key2")), p.getMinimumToken()));
StreamOutSession session = StreamOutSession.create(table.name, LOCAL, null);
StreamOut.transferSSTables(session, Arrays.asList(sstable), ranges, OperationType.BOOTSTRAP);
session.await();
}
use of org.apache.cassandra.dht.IPartitioner 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.IPartitioner 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);
}
}
use of org.apache.cassandra.dht.IPartitioner in project cassandra by apache.
the class SimpleStrategyTest method testStringEndpoints.
@Test
public void testStringEndpoints() throws UnknownHostException {
IPartitioner partitioner = OrderPreservingPartitioner.instance;
List<Token> endpointTokens = new ArrayList<Token>();
List<Token> keyTokens = new ArrayList<Token>();
for (int i = 0; i < 5; i++) {
endpointTokens.add(new StringToken(String.valueOf((char) ('a' + i * 2))));
keyTokens.add(partitioner.getToken(ByteBufferUtil.bytes(String.valueOf((char) ('a' + i * 2 + 1)))));
}
verifyGetNaturalEndpoints(endpointTokens.toArray(new Token[0]), keyTokens.toArray(new Token[0]));
}
Aggregations