use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class MutationVerbHandler method doVerb.
public void doVerb(Message<Mutation> message) {
// Check if there were any forwarding headers in this message
InetAddressAndPort from = message.respondTo();
InetAddressAndPort respondToAddress;
if (from == null) {
respondToAddress = message.from();
ForwardingInfo forwardTo = message.forwardTo();
if (forwardTo != null)
forwardToLocalNodes(message, forwardTo);
} else {
respondToAddress = from;
}
try {
message.payload.applyFuture().addCallback(o -> respond(message, respondToAddress), wto -> failed());
} catch (WriteTimeoutException wto) {
failed();
}
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class MigrationManager method resetLocalSchema.
/**
* Clear all locally stored schema information and reset schema to initial state.
* Called by user (via JMX) who wants to get rid of schema disagreement.
*/
public static void resetLocalSchema() {
logger.info("Starting local schema reset...");
logger.debug("Truncating schema tables...");
SchemaMigrationDiagnostics.resetLocalSchema();
Schema.instance.truncateSchemaKeyspace();
logger.debug("Clearing local schema keyspace definitions...");
Schema.instance.clear();
Set<InetAddressAndPort> liveEndpoints = Gossiper.instance.getLiveMembers();
liveEndpoints.remove(FBUtilities.getBroadcastAddressAndPort());
// force migration if there are nodes around
for (InetAddressAndPort node : liveEndpoints) {
EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(node);
Future<Void> pull = MigrationCoordinator.instance.reportEndpointVersion(node, state);
if (pull != null)
FBUtilities.waitOnFuture(pull);
}
logger.info("Local schema reset is complete.");
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class MigrationManager method announce.
public static void announce(Collection<Mutation> schema) {
Future<?> f = announceWithoutPush(schema);
Set<InetAddressAndPort> schemaDestinationEndpoints = new HashSet<>();
Set<InetAddressAndPort> schemaEndpointsIgnored = new HashSet<>();
Message<Collection<Mutation>> message = Message.out(SCHEMA_PUSH_REQ, schema);
for (InetAddressAndPort endpoint : Gossiper.instance.getLiveMembers()) {
if (shouldPushSchemaTo(endpoint)) {
MessagingService.instance().send(message, endpoint);
schemaDestinationEndpoints.add(endpoint);
} else {
schemaEndpointsIgnored.add(endpoint);
}
}
SchemaAnnouncementDiagnostics.schemaMutationsAnnounced(schemaDestinationEndpoints, schemaEndpointsIgnored);
FBUtilities.waitOnFuture(f);
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class PendingRangesBench method setUp.
@Setup
public void setUp() throws UnknownHostException {
pendingRangeMaps = new PendingRangeMaps();
oldPendingRanges = HashMultimap.create();
List<InetAddressAndPort> endpoints = Lists.newArrayList(InetAddressAndPort.getByName("127.0.0.1"), InetAddressAndPort.getByName("127.0.0.2"));
for (int i = 0; i < maxToken; i++) {
for (int j = 0; j < ThreadLocalRandom.current().nextInt(2); j++) {
Range<Token> range = genRange(Integer.toString(i * 10 + 5), Integer.toString(i * 10 + 15));
Replica replica = Replica.fullReplica(endpoints.get(j), range);
pendingRangeMaps.addPendingRange(range, replica);
oldPendingRanges.put(range, replica);
}
}
// add the wrap around range
for (int j = 0; j < ThreadLocalRandom.current().nextInt(2); j++) {
Range<Token> range = genRange(Integer.toString(maxToken * 10 + 5), Integer.toString(5));
Replica replica = Replica.fullReplica(endpoints.get(j), range);
pendingRangeMaps.addPendingRange(range, replica);
oldPendingRanges.put(range, replica);
}
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class AlterTest method testDefaultRF.
@Test
public void testDefaultRF() throws Throwable {
TokenMetadata metadata = StorageService.instance.getTokenMetadata();
metadata.clearUnsafe();
InetAddressAndPort local = FBUtilities.getBroadcastAddressAndPort();
InetAddressAndPort remote = InetAddressAndPort.getByName("127.0.0.4");
metadata.updateHostId(UUID.randomUUID(), local);
metadata.updateNormalToken(new OrderPreservingPartitioner.StringToken("A"), local);
metadata.updateHostId(UUID.randomUUID(), remote);
metadata.updateNormalToken(new OrderPreservingPartitioner.StringToken("B"), remote);
DatabaseDescriptor.setDefaultKeyspaceRF(3);
// ensure default rf is being taken into account during creation, and user can choose to override the default
String ks1 = createKeyspace("CREATE KEYSPACE %s WITH replication={ 'class' : 'SimpleStrategy' }");
String ks2 = createKeyspace("CREATE KEYSPACE %s WITH replication={ 'class' : 'SimpleStrategy', 'replication_factor' : 2 }");
String ks3 = createKeyspace("CREATE KEYSPACE %s WITH replication={ 'class' : 'NetworkTopologyStrategy' }");
String ks4 = createKeyspace("CREATE KEYSPACE %s WITH replication={ 'class' : 'NetworkTopologyStrategy', 'replication_factor' : 2 }");
assertRowsIgnoringOrderAndExtra(execute("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces"), row(ks1, true, map("class", "org.apache.cassandra.locator.SimpleStrategy", "replication_factor", Integer.toString(DatabaseDescriptor.getDefaultKeyspaceRF()))), row(ks2, true, map("class", "org.apache.cassandra.locator.SimpleStrategy", "replication_factor", "2")), row(ks3, true, map("class", "org.apache.cassandra.locator.NetworkTopologyStrategy", DATA_CENTER, Integer.toString(DatabaseDescriptor.getDefaultKeyspaceRF()), DATA_CENTER_REMOTE, Integer.toString(DatabaseDescriptor.getDefaultKeyspaceRF()))), row(ks4, true, map("class", "org.apache.cassandra.locator.NetworkTopologyStrategy", DATA_CENTER, "2", DATA_CENTER_REMOTE, "2")));
// ensure alter keyspace does not default to default rf unless altering from NTS to SS
// no change alter
schemaChange("ALTER KEYSPACE " + ks4 + " WITH durable_writes=true");
assertRowsIgnoringOrderAndExtra(execute("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces"), row(ks4, true, map("class", "org.apache.cassandra.locator.NetworkTopologyStrategy", DATA_CENTER, "2", DATA_CENTER_REMOTE, "2")));
schemaChange("ALTER KEYSPACE " + ks4 + " WITH replication={ 'class' : 'NetworkTopologyStrategy' }");
assertRowsIgnoringOrderAndExtra(execute("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces"), row(ks4, true, map("class", "org.apache.cassandra.locator.NetworkTopologyStrategy", DATA_CENTER, "2", DATA_CENTER_REMOTE, "2")));
// change from SS to NTS
// without specifying RF
schemaChange("ALTER KEYSPACE " + ks2 + " WITH replication={ 'class' : 'NetworkTopologyStrategy' } AND durable_writes=true");
// verify that RF of SS is retained
assertRowsIgnoringOrderAndExtra(execute("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces"), row(ks2, true, map("class", "org.apache.cassandra.locator.NetworkTopologyStrategy", DATA_CENTER, "2", DATA_CENTER_REMOTE, "2")));
// with specifying RF
schemaChange("ALTER KEYSPACE " + ks1 + " WITH replication={ 'class' : 'NetworkTopologyStrategy', 'replication_factor': '1' } AND durable_writes=true");
// verify that explicitly mentioned RF is taken into account
assertRowsIgnoringOrderAndExtra(execute("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces"), row(ks1, true, map("class", "org.apache.cassandra.locator.NetworkTopologyStrategy", DATA_CENTER, "1", DATA_CENTER_REMOTE, "1")));
// change from NTS to SS
// without specifying RF
schemaChange("ALTER KEYSPACE " + ks4 + " WITH replication={ 'class' : 'SimpleStrategy' } AND durable_writes=true");
// verify that default RF is taken into account
assertRowsIgnoringOrderAndExtra(execute("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces"), row(ks4, true, map("class", "org.apache.cassandra.locator.SimpleStrategy", "replication_factor", Integer.toString(DatabaseDescriptor.getDefaultKeyspaceRF()))));
// with specifying RF
schemaChange("ALTER KEYSPACE " + ks3 + " WITH replication={ 'class' : 'SimpleStrategy', 'replication_factor' : '1' } AND durable_writes=true");
// verify that explicitly mentioned RF is taken into account
assertRowsIgnoringOrderAndExtra(execute("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces"), row(ks3, true, map("class", "org.apache.cassandra.locator.SimpleStrategy", "replication_factor", "1")));
// verify updated default does not effect existing keyspaces
// create keyspaces
String ks5 = createKeyspace("CREATE KEYSPACE %s WITH replication={ 'class' : 'SimpleStrategy' }");
String ks6 = createKeyspace("CREATE KEYSPACE %s WITH replication={ 'class' : 'NetworkTopologyStrategy' }");
String oldRF = Integer.toString(DatabaseDescriptor.getDefaultKeyspaceRF());
// change default
DatabaseDescriptor.setDefaultKeyspaceRF(2);
// verify RF of existing keyspaces
assertRowsIgnoringOrderAndExtra(execute("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces"), row(ks5, true, map("class", "org.apache.cassandra.locator.SimpleStrategy", "replication_factor", oldRF)));
assertRowsIgnoringOrderAndExtra(execute("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces"), row(ks6, true, map("class", "org.apache.cassandra.locator.NetworkTopologyStrategy", DATA_CENTER, oldRF, DATA_CENTER_REMOTE, oldRF)));
// clean up config change
DatabaseDescriptor.setDefaultKeyspaceRF(1);
// clean up keyspaces
execute(String.format("DROP KEYSPACE IF EXISTS %s", ks1));
execute(String.format("DROP KEYSPACE IF EXISTS %s", ks2));
execute(String.format("DROP KEYSPACE IF EXISTS %s", ks3));
execute(String.format("DROP KEYSPACE IF EXISTS %s", ks4));
execute(String.format("DROP KEYSPACE IF EXISTS %s", ks5));
execute(String.format("DROP KEYSPACE IF EXISTS %s", ks6));
}
Aggregations