use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class DistributedTestSnitch method toCassandraInetAddressAndPort.
public static InetAddressAndPort toCassandraInetAddressAndPort(InetSocketAddress addressAndPort) {
InetAddressAndPort m = cacheInverse.get(addressAndPort);
if (m == null) {
m = InetAddressAndPort.getByAddressOverrideDefaults(addressAndPort.getAddress(), addressAndPort.getPort());
cache.put(m, addressAndPort);
}
return m;
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class SimulatedAction method applyToMessage.
Action applyToMessage(IInvokableInstance from, IInvokableInstance to, IMessage message) {
Executor executor = to.executorFor(message.verb());
if (executor instanceof ImmediateExecutor)
executor = to.executor();
InterceptedExecution.InterceptedTaskExecution task = new InterceptedRunnableExecution((InterceptingExecutor) executor, () -> to.receiveMessageWithInvokingThread(message));
Verb verb = Verb.fromId(message.verb());
Modifiers self = verbModifiers.getOrDefault(verb, NONE);
int fromNum = from.config().num();
int toNum = to.config().num();
Deliver deliver;
if (is(Modifier.RELIABLE) || self.is(Modifier.RELIABLE))
deliver = DELIVER;
else
deliver = simulated.futureScheduler.shouldDeliver(fromNum, toNum);
Action action;
switch(deliver) {
default:
throw new AssertionError();
case DELIVER:
{
Object description = lazy(() -> String.format("%s(%d) from %s to %s", Verb.fromId(message.verb()), message.id(), message.from(), to.broadcastAddress()));
OrderOn orderOn = task.executor.orderAppliesAfterScheduling();
action = applyTo(description, MESSAGE, orderOn, self, verb, task);
action.setDeadline(simulated.futureScheduler.messageDeadlineNanos(fromNum, toNum));
break;
}
case FAILURE:
case TIMEOUT:
{
task.cancel();
self = DROP.with(self);
InetSocketAddress failedOn;
IInvokableInstance notify;
if (verb.isResponse()) {
failedOn = from.broadcastAddress();
notify = to;
} else {
failedOn = to.broadcastAddress();
notify = from;
}
InterceptedExecution.InterceptedTaskExecution failTask = new InterceptedRunnableExecution((InterceptingExecutor) notify.executorFor(verb.id), () -> notify.unsafeApplyOnThisThread((socketAddress, id, isTimeout) -> {
InetAddressAndPort address = InetAddressAndPort.getByAddress(socketAddress);
RequestCallbacks.CallbackInfo callback = instance().callbacks.remove(id, address);
if (callback != null) {
RequestCallback<?> invokeOn = (RequestCallback<?>) callback.callback;
RequestFailureReason reason = isTimeout ? RequestFailureReason.TIMEOUT : RequestFailureReason.UNKNOWN;
invokeOn.onFailure(address, reason);
}
return null;
}, failedOn, message.id(), deliver == TIMEOUT));
Object description = (lazy(() -> String.format("Report Timeout of %s(%d) from %s to %s", Verb.fromId(message.verb()), message.id(), failedOn, notify.broadcastAddress())));
OrderOn orderOn = failTask.executor.orderAppliesAfterScheduling();
action = applyTo(description, MESSAGE, orderOn, self, failTask);
switch(deliver) {
default:
throw new AssertionError();
case TIMEOUT:
long expiresAfterNanos = from.unsafeApplyOnThisThread(id -> Verb.fromId(id).expiresAfterNanos(), (verb.isResponse() ? forVerb : verb).id);
action.setDeadline(simulated.futureScheduler.messageTimeoutNanos(expiresAfterNanos));
break;
case FAILURE:
action.setDeadline(simulated.futureScheduler.messageFailureNanos(toNum, fromNum));
break;
}
break;
}
}
return action;
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class CompactionIteratorTest method duplicateRowsTest.
@Test
public void duplicateRowsTest() throws Throwable {
System.setProperty("cassandra.diagnostic_snapshot_interval_nanos", "0");
// Create a table and insert some data. The actual rows read in the test will be synthetic
// but this creates an sstable on disk to be snapshotted.
createTable("CREATE TABLE %s (pk text, ck1 int, ck2 int, v int, PRIMARY KEY (pk, ck1, ck2))");
for (int i = 0; i < 10; i++) execute("insert into %s (pk, ck1, ck2, v) values (?, ?, ?, ?)", "key", i, i, i);
getCurrentColumnFamilyStore().forceBlockingFlush();
DatabaseDescriptor.setSnapshotOnDuplicateRowDetection(true);
TableMetadata metadata = getCurrentColumnFamilyStore().metadata();
final HashMap<InetAddressAndPort, Message<?>> sentMessages = new HashMap<>();
MessagingService.instance().outboundSink.add((message, to) -> {
sentMessages.put(to, message);
return false;
});
// no duplicates
sentMessages.clear();
iterate(makeRow(metadata, 0, 0), makeRow(metadata, 0, 1), makeRow(metadata, 0, 2));
assertCommandIssued(sentMessages, false);
// now test with a duplicate row and see that we issue a snapshot command
sentMessages.clear();
iterate(makeRow(metadata, 0, 0), makeRow(metadata, 0, 1), makeRow(metadata, 0, 1));
assertCommandIssued(sentMessages, true);
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class CancelCompactionsTest method testAnticompaction.
@Test
public void testAnticompaction() throws InterruptedException, ExecutionException {
ColumnFamilyStore cfs = MockSchema.newCFS();
List<SSTableReader> sstables = createSSTables(cfs, 10, 0);
List<SSTableReader> alreadyRepairedSSTables = createSSTables(cfs, 10, 10);
for (SSTableReader sstable : alreadyRepairedSSTables) AbstractPendingRepairTest.mutateRepaired(sstable, System.currentTimeMillis());
assertEquals(20, cfs.getLiveSSTables().size());
List<TestCompactionTask> tcts = new ArrayList<>();
tcts.add(new TestCompactionTask(cfs, new HashSet<>(sstables.subList(0, 2))));
tcts.add(new TestCompactionTask(cfs, new HashSet<>(sstables.subList(3, 4))));
tcts.add(new TestCompactionTask(cfs, new HashSet<>(sstables.subList(5, 7))));
tcts.add(new TestCompactionTask(cfs, new HashSet<>(sstables.subList(8, 9))));
List<TestCompactionTask> nonAffectedTcts = new ArrayList<>();
nonAffectedTcts.add(new TestCompactionTask(cfs, new HashSet<>(alreadyRepairedSSTables)));
try {
tcts.forEach(TestCompactionTask::start);
nonAffectedTcts.forEach(TestCompactionTask::start);
List<CompactionInfo.Holder> activeCompactions = getActiveCompactionsForTable(cfs);
assertEquals(5, activeCompactions.size());
// make sure that sstables are fully contained so that the metadata gets mutated
Range<Token> range = new Range<>(token(-1), token(49));
UUID prsid = UUID.randomUUID();
ActiveRepairService.instance.registerParentRepairSession(prsid, InetAddressAndPort.getLocalHost(), Collections.singletonList(cfs), Collections.singleton(range), true, 1, true, PreviewKind.NONE);
InetAddressAndPort local = FBUtilities.getBroadcastAddressAndPort();
RangesAtEndpoint rae = RangesAtEndpoint.builder(local).add(new Replica(local, range, true)).build();
PendingAntiCompaction pac = new PendingAntiCompaction(prsid, Collections.singleton(cfs), rae, Executors.newSingleThreadExecutor(), () -> false);
Future<?> fut = pac.run();
Thread.sleep(600);
List<TestCompactionTask> toAbort = new ArrayList<>();
for (CompactionInfo.Holder holder : getActiveCompactionsForTable(cfs)) {
if (holder.getCompactionInfo().getSSTables().stream().anyMatch(sstable -> sstable.intersects(Collections.singleton(range)) && !sstable.isRepaired() && !sstable.isPendingRepair())) {
assertTrue(holder.isStopRequested());
for (TestCompactionTask tct : tcts) if (tct.sstables.equals(holder.getCompactionInfo().getSSTables()))
toAbort.add(tct);
} else
assertFalse(holder.isStopRequested());
}
assertEquals(2, toAbort.size());
toAbort.forEach(TestCompactionTask::abort);
fut.get();
for (SSTableReader sstable : sstables) assertTrue(!sstable.intersects(Collections.singleton(range)) || sstable.isPendingRepair());
} finally {
tcts.forEach(TestCompactionTask::abort);
nonAffectedTcts.forEach(TestCompactionTask::abort);
}
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class SystemKeyspace method loadTokens.
/**
* Return a map of stored tokens to IP addresses
*/
public static SetMultimap<InetAddressAndPort, Token> loadTokens() {
SetMultimap<InetAddressAndPort, Token> tokenMap = HashMultimap.create();
for (UntypedResultSet.Row row : executeInternal("SELECT peer, peer_port, tokens FROM system." + PEERS_V2)) {
InetAddress address = row.getInetAddress("peer");
Integer port = row.getInt("peer_port");
InetAddressAndPort peer = InetAddressAndPort.getByAddressOverrideDefaults(address, port);
if (row.has("tokens"))
tokenMap.putAll(peer, deserializeTokens(row.getSet("tokens", UTF8Type.instance)));
}
return tokenMap;
}
Aggregations