use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class CassandraEntireSSTableStreamWriterTest method setupStreamingSessionForTest.
private StreamSession setupStreamingSessionForTest() {
StreamCoordinator streamCoordinator = new StreamCoordinator(StreamOperation.BOOTSTRAP, 1, new NettyStreamingConnectionFactory(), false, false, null, PreviewKind.NONE);
StreamResultFuture future = StreamResultFuture.createInitiator(UUID.randomUUID(), StreamOperation.BOOTSTRAP, Collections.<StreamEventHandler>emptyList(), streamCoordinator);
InetAddressAndPort peer = FBUtilities.getBroadcastAddressAndPort();
streamCoordinator.addSessionInfo(new SessionInfo(peer, 0, peer, Collections.emptyList(), Collections.emptyList(), StreamSession.State.INITIALIZED));
StreamSession session = streamCoordinator.getOrCreateOutboundSession(peer);
session.init(future);
return session;
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class CassandraEntireSSTableStreamWriterTest method testBlockReadingAndWritingOverWire.
@Test
public void testBlockReadingAndWritingOverWire() throws Throwable {
StreamSession session = setupStreamingSessionForTest();
InetAddressAndPort peer = FBUtilities.getBroadcastAddressAndPort();
// This is needed as Netty releases the ByteBuffers as soon as the channel is flushed
ByteBuf serializedFile = Unpooled.buffer(8192);
EmbeddedChannel channel = createMockNettyChannel(serializedFile);
try (AsyncStreamingOutputPlus out = new AsyncStreamingOutputPlus(channel);
ComponentContext context = ComponentContext.create(descriptor)) {
CassandraEntireSSTableStreamWriter writer = new CassandraEntireSSTableStreamWriter(sstable, session, context);
writer.write(out);
session.prepareReceiving(new StreamSummary(sstable.metadata().id, 1, 5104));
CassandraStreamHeader header = CassandraStreamHeader.builder().withSSTableFormat(sstable.descriptor.formatType).withSSTableVersion(sstable.descriptor.version).withSSTableLevel(0).withEstimatedKeys(sstable.estimatedKeys()).withSections(Collections.emptyList()).withSerializationHeader(sstable.header.toComponent()).withComponentManifest(context.manifest()).isEntireSSTable(true).withFirstKey(sstable.first).withTableId(sstable.metadata().id).build();
CassandraEntireSSTableStreamReader reader = new CassandraEntireSSTableStreamReader(new StreamMessageHeader(sstable.metadata().id, peer, session.planId(), false, 0, 0, 0, null), header, session);
SSTableMultiWriter sstableWriter = reader.read(new DataInputBuffer(serializedFile.nioBuffer(), false));
Collection<SSTableReader> newSstables = sstableWriter.finished();
assertEquals(1, newSstables.size());
}
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class ExpireEndpointTest method testExpireEndpoint.
@Test
public void testExpireEndpoint() throws UnknownHostException {
InetAddressAndPort hostAddress = InetAddressAndPort.getByName("127.0.0.2");
UUID hostId = UUID.randomUUID();
long expireTime = System.currentTimeMillis() - 1;
Gossiper.instance.initializeNodeUnsafe(hostAddress, hostId, 1);
EndpointState endpointState = Gossiper.instance.getEndpointStateForEndpoint(hostAddress);
Gossiper.runInGossipStageBlocking(() -> Gossiper.instance.markDead(hostAddress, endpointState));
endpointState.addApplicationState(ApplicationState.STATUS_WITH_PORT, StorageService.instance.valueFactory.removedNonlocal(hostId, expireTime));
Gossiper.instance.addExpireTimeForEndpoint(hostAddress, expireTime);
assertTrue("Expiring endpoint not unreachable before status check", Gossiper.instance.getUnreachableMembers().contains(hostAddress));
Gossiper.instance.doStatusCheck();
assertFalse("Expired endpoint still part of live members", Gossiper.instance.getLiveMembers().contains(hostAddress));
assertFalse("Expired endpoint still part of unreachable members", Gossiper.instance.getUnreachableMembers().contains(hostAddress));
assertNull("Expired endpoint still contain endpoint state", Gossiper.instance.getEndpointStateForEndpoint(hostAddress));
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class GossiperTest method testLargeGenerationJump.
@Test
public void testLargeGenerationJump() throws UnknownHostException, InterruptedException {
Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 2);
try {
InetAddressAndPort remoteHostAddress = hosts.get(1);
EndpointState initialRemoteState = Gossiper.instance.getEndpointStateForEndpoint(remoteHostAddress);
HeartBeatState initialRemoteHeartBeat = initialRemoteState.getHeartBeatState();
// Util.createInitialRing should have initialized remoteHost's HeartBeatState's generation to 1
assertEquals(initialRemoteHeartBeat.getGeneration(), 1);
HeartBeatState proposedRemoteHeartBeat = new HeartBeatState(initialRemoteHeartBeat.getGeneration() + Gossiper.MAX_GENERATION_DIFFERENCE + 1);
EndpointState proposedRemoteState = new EndpointState(proposedRemoteHeartBeat);
Gossiper.instance.applyStateLocally(ImmutableMap.of(remoteHostAddress, proposedRemoteState));
// The generation should have been updated because it isn't over Gossiper.MAX_GENERATION_DIFFERENCE in the future
HeartBeatState actualRemoteHeartBeat = Gossiper.instance.getEndpointStateForEndpoint(remoteHostAddress).getHeartBeatState();
assertEquals(proposedRemoteHeartBeat.getGeneration(), actualRemoteHeartBeat.getGeneration());
// Propose a generation 10 years in the future - this should be rejected.
HeartBeatState badProposedRemoteHeartBeat = new HeartBeatState((int) (System.currentTimeMillis() / 1000) + Gossiper.MAX_GENERATION_DIFFERENCE * 10);
EndpointState badProposedRemoteState = new EndpointState(badProposedRemoteHeartBeat);
Gossiper.instance.applyStateLocally(ImmutableMap.of(remoteHostAddress, badProposedRemoteState));
actualRemoteHeartBeat = Gossiper.instance.getEndpointStateForEndpoint(remoteHostAddress).getHeartBeatState();
// The generation should not have been updated because it is over Gossiper.MAX_GENERATION_DIFFERENCE in the future
assertEquals(proposedRemoteHeartBeat.getGeneration(), actualRemoteHeartBeat.getGeneration());
} finally {
// clean up the gossip states
Gossiper.instance.endpointStateMap.clear();
}
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class GossiperTest method testNotFireDuplicatedNotificationsWithUpdateContainsOldAndNewState.
@Test
public void testNotFireDuplicatedNotificationsWithUpdateContainsOldAndNewState() throws UnknownHostException {
VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(DatabaseDescriptor.getPartitioner());
Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 2);
SimpleStateChangeListener stateChangeListener = null;
try {
InetAddressAndPort remoteHostAddress = hosts.get(1);
EndpointState initialRemoteState = Gossiper.instance.getEndpointStateForEndpoint(remoteHostAddress);
HeartBeatState initialRemoteHeartBeat = initialRemoteState.getHeartBeatState();
// Util.createInitialRing should have initialized remoteHost's HeartBeatState's generation to 1
assertEquals(initialRemoteHeartBeat.getGeneration(), 1);
// Test begins
AtomicInteger notificationCount = new AtomicInteger(0);
HeartBeatState proposedRemoteHeartBeat = new HeartBeatState(initialRemoteHeartBeat.getGeneration());
EndpointState proposedRemoteState = new EndpointState(proposedRemoteHeartBeat);
final Token token = DatabaseDescriptor.getPartitioner().getRandomToken();
proposedRemoteState.addApplicationState(ApplicationState.STATUS, valueFactory.normal(Collections.singletonList(token)));
stateChangeListener = new SimpleStateChangeListener();
Gossiper.instance.register(stateChangeListener);
// STEP 1. register verifier and apply state with just STATUS
// simulate applying gossip state from a v3 peer
stateChangeListener.setOnChangeVerifier(onChangeParams -> {
notificationCount.getAndIncrement();
assertEquals("It should fire notification for STATUS when gossiper local state not yet has STATUS_WITH_PORT", ApplicationState.STATUS, onChangeParams.state);
});
Gossiper.instance.applyStateLocally(ImmutableMap.of(remoteHostAddress, proposedRemoteState));
// STEP 2. includes both STATUS and STATUS_WITH_PORT. The gossiper knows that the remote peer is now in v4
// update verifier and apply state again
proposedRemoteState.addApplicationState(ApplicationState.STATUS_WITH_PORT, valueFactory.normal(Collections.singletonList(token)));
stateChangeListener.setOnChangeVerifier(onChangeParams -> {
notificationCount.getAndIncrement();
assertEquals("It should only fire notification for STATUS_WITH_PORT", ApplicationState.STATUS_WITH_PORT, onChangeParams.state);
});
Gossiper.instance.applyStateLocally(ImmutableMap.of(remoteHostAddress, proposedRemoteState));
// STEP 3. somehow, the peer send only the STATUS in the update.
proposedRemoteState = new EndpointState(proposedRemoteHeartBeat);
proposedRemoteState.addApplicationState(ApplicationState.STATUS, valueFactory.normal(Collections.singletonList(token)));
stateChangeListener.setOnChangeVerifier(onChangeParams -> {
notificationCount.getAndIncrement();
fail("It should not fire notification for STATUS");
});
assertEquals("Expect exact 2 notifications with the test setup", 2, notificationCount.get());
} finally {
// clean up the gossip states
Gossiper.instance.endpointStateMap.clear();
if (stateChangeListener != null)
Gossiper.instance.unregister(stateChangeListener);
}
}
Aggregations