本文整理汇总了Java中org.apache.cassandra.gms.FailureDetector类的典型用法代码示例。如果您正苦于以下问题:Java FailureDetector类的具体用法?Java FailureDetector怎么用?Java FailureDetector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FailureDetector类属于org.apache.cassandra.gms包,在下文中一共展示了FailureDetector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendReplicationNotification
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
/**
* Sends a notification to a node indicating we have finished replicating data.
*
* @param remote node to send notification to
*/
private void sendReplicationNotification(InetAddress remote)
{
// notify the remote token
MessageOut msg = new MessageOut(MessagingService.Verb.REPLICATION_FINISHED);
IFailureDetector failureDetector = FailureDetector.instance;
if (logger.isDebugEnabled())
logger.debug("Notifying {} of replication completion\n", remote);
while (failureDetector.isAlive(remote))
{
AsyncOneResponse iar = MessagingService.instance().sendRR(msg, remote);
try
{
iar.get(DatabaseDescriptor.getRpcTimeout(), TimeUnit.MILLISECONDS);
return; // done
}
catch(TimeoutException e)
{
// try again
}
}
}
示例2: commitPaxos
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
private static void commitPaxos(Commit proposal, ConsistencyLevel consistencyLevel) throws WriteTimeoutException
{
Keyspace keyspace = Keyspace.open(proposal.update.metadata().ksName);
Token tk = StorageService.getPartitioner().getToken(proposal.key);
List<InetAddress> naturalEndpoints = StorageService.instance.getNaturalEndpoints(keyspace.getName(), tk);
Collection<InetAddress> pendingEndpoints = StorageService.instance.getTokenMetadata().pendingEndpointsFor(tk, keyspace.getName());
AbstractReplicationStrategy rs = keyspace.getReplicationStrategy();
AbstractWriteResponseHandler responseHandler = rs.getWriteResponseHandler(naturalEndpoints, pendingEndpoints, consistencyLevel, null, WriteType.SIMPLE);
MessageOut<Commit> message = new MessageOut<Commit>(MessagingService.Verb.PAXOS_COMMIT, proposal, Commit.serializer);
for (InetAddress destination : Iterables.concat(naturalEndpoints, pendingEndpoints))
{
if (FailureDetector.instance.isAlive(destination))
MessagingService.instance().sendRR(message, destination, responseHandler);
}
responseHandler.get();
}
示例3: replaySerializedMutation
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
private void replaySerializedMutation(RowMutation mutation, long writtenAt)
{
int ttl = calculateHintTTL(mutation, writtenAt);
if (ttl <= 0)
return; // the mutation isn't safe to replay.
Set<InetAddress> liveEndpoints = new HashSet<InetAddress>();
String ks = mutation.getKeyspaceName();
Token<?> tk = StorageService.getPartitioner().getToken(mutation.key());
for (InetAddress endpoint : Iterables.concat(StorageService.instance.getNaturalEndpoints(ks, tk),
StorageService.instance.getTokenMetadata().pendingEndpointsFor(tk, ks)))
{
if (endpoint.equals(FBUtilities.getBroadcastAddress()))
mutation.apply();
else if (FailureDetector.instance.isAlive(endpoint))
liveEndpoints.add(endpoint); // will try delivering directly instead of writing a hint.
else
StorageProxy.writeHintForMutation(mutation, ttl, endpoint);
}
if (!liveEndpoints.isEmpty())
attemptDirectDelivery(mutation, writtenAt, liveEndpoints);
}
示例4: run
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
public void run()
{
if (FailureDetector.instance.isAlive(neighbor))
{
AnticompactionRequest acr = new AnticompactionRequest(parentSession, successfulRanges);
CassandraVersion peerVersion = SystemKeyspace.getReleaseVersion(neighbor);
if (peerVersion != null && peerVersion.compareTo(VERSION_CHECKER) > 0)
{
MessagingService.instance().sendRR(acr.createMessage(), neighbor, new AnticompactionCallback(this), TimeUnit.DAYS.toMillis(1), true);
}
else
{
MessagingService.instance().sendOneWay(acr.createMessage(), neighbor);
// immediately return after sending request
set(neighbor);
}
}
else
{
setException(new IOException(neighbor + " is down"));
}
}
示例5: bootstrap
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
public void bootstrap()
{
if (logger.isDebugEnabled())
logger.debug("Beginning bootstrap process");
RangeStreamer streamer = new RangeStreamer(tokenMetadata, address, OperationType.BOOTSTRAP);
streamer.addSourceFilter(new RangeStreamer.FailureDetectorSourceFilter(FailureDetector.instance));
for (String table : Schema.instance.getNonSystemTables())
{
AbstractReplicationStrategy strategy = Table.open(table).getReplicationStrategy();
streamer.addRanges(table, strategy.getPendingAddressRanges(tokenMetadata, tokens, address));
}
streamer.fetch();
StorageService.instance.finishBootstrapping();
}
示例6: replaySerializedMutation
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
private void replaySerializedMutation(RowMutation mutation, long writtenAt) throws IOException
{
int ttl = calculateHintTTL(mutation, writtenAt);
if (ttl <= 0)
return; // the mutation isn't safe to replay.
Set<InetAddress> liveEndpoints = new HashSet<InetAddress>();
String ks = mutation.getTable();
Token tk = StorageService.getPartitioner().getToken(mutation.key());
for (InetAddress endpoint : Iterables.concat(StorageService.instance.getNaturalEndpoints(ks, tk),
StorageService.instance.getTokenMetadata().pendingEndpointsFor(tk, ks)))
{
if (endpoint.equals(FBUtilities.getBroadcastAddress()))
mutation.apply();
else if (FailureDetector.instance.isAlive(endpoint))
liveEndpoints.add(endpoint); // will try delivering directly instead of writing a hint.
else
StorageProxy.writeHintForMutation(mutation, ttl, endpoint);
}
if (!liveEndpoints.isEmpty())
attemptDirectDelivery(mutation, writtenAt, liveEndpoints);
}
示例7: replaySerializedMutation
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
private void replaySerializedMutation(Mutation mutation, long writtenAt, RateLimiter rateLimiter)
{
int ttl = calculateHintTTL(mutation, writtenAt);
if (ttl <= 0)
return; // the mutation isn't safe to replay.
Set<InetAddress> liveEndpoints = new HashSet<>();
String ks = mutation.getKeyspaceName();
Token<?> tk = StorageService.getPartitioner().getToken(mutation.key());
int mutationSize = (int) Mutation.serializer.serializedSize(mutation, VERSION);
for (InetAddress endpoint : Iterables.concat(StorageService.instance.getNaturalEndpoints(ks, tk),
StorageService.instance.getTokenMetadata().pendingEndpointsFor(tk, ks)))
{
rateLimiter.acquire(mutationSize);
if (endpoint.equals(FBUtilities.getBroadcastAddress()))
mutation.apply();
else if (FailureDetector.instance.isAlive(endpoint))
liveEndpoints.add(endpoint); // will try delivering directly instead of writing a hint.
else
StorageProxy.writeHintForMutation(mutation, ttl, endpoint);
}
if (!liveEndpoints.isEmpty())
attemptDirectDelivery(mutation, writtenAt, liveEndpoints);
}
示例8: replaySerializedMutation
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
private void replaySerializedMutation(Mutation mutation, long writtenAt, int version, RateLimiter rateLimiter)
{
int ttl = calculateHintTTL(mutation, writtenAt);
if (ttl <= 0)
return; // the mutation isn't safe to replay.
Set<InetAddress> liveEndpoints = new HashSet<>();
String ks = mutation.getKeyspaceName();
Token<?> tk = StorageService.getPartitioner().getToken(mutation.key());
int mutationSize = (int) Mutation.serializer.serializedSize(mutation, version);
for (InetAddress endpoint : Iterables.concat(StorageService.instance.getNaturalEndpoints(ks, tk),
StorageService.instance.getTokenMetadata().pendingEndpointsFor(tk, ks)))
{
rateLimiter.acquire(mutationSize);
if (endpoint.equals(FBUtilities.getBroadcastAddress()))
mutation.apply();
else if (FailureDetector.instance.isAlive(endpoint))
liveEndpoints.add(endpoint); // will try delivering directly instead of writing a hint.
else
StorageProxy.writeHintForMutation(mutation, ttl, endpoint);
}
if (!liveEndpoints.isEmpty())
attemptDirectDelivery(mutation, writtenAt, liveEndpoints);
}
示例9: replaySerializedMutation
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
private void replaySerializedMutation(RowMutation mutation, long writtenAt, RateLimiter rateLimiter) throws IOException
{
int ttl = calculateHintTTL(mutation, writtenAt);
if (ttl <= 0)
return; // the mutation isn't safe to replay.
Set<InetAddress> liveEndpoints = new HashSet<InetAddress>();
String ks = mutation.getTable();
Token tk = StorageService.getPartitioner().getToken(mutation.key());
int mutationSize = (int) RowMutation.serializer.serializedSize(mutation, VERSION);
for (InetAddress endpoint : Iterables.concat(StorageService.instance.getNaturalEndpoints(ks, tk),
StorageService.instance.getTokenMetadata().pendingEndpointsFor(tk, ks)))
{
rateLimiter.acquire(mutationSize);
if (endpoint.equals(FBUtilities.getBroadcastAddress()))
mutation.apply();
else if (FailureDetector.instance.isAlive(endpoint))
liveEndpoints.add(endpoint); // will try delivering directly instead of writing a hint.
else
StorageProxy.writeHintForMutation(mutation, ttl, endpoint);
}
if (!liveEndpoints.isEmpty())
attemptDirectDelivery(mutation, writtenAt, liveEndpoints);
}
示例10: main
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
System.out.println("Connecting to " + config.getBaseUrl());
System.out.println("Starting the JMX server");
MBeanServer server = getPlatformMBeanServer();
for (Class<? extends APIMBean> clazz : asList(StorageService.class, StorageProxy.class, MessagingService.class,
CommitLog.class, Gossiper.class, EndpointSnitchInfo.class, FailureDetector.class, CacheService.class,
CompactionManager.class, GCInspector.class, StreamManager.class)) {
Constructor<? extends APIMBean> c = clazz.getDeclaredConstructor(APIClient.class);
APIMBean m = c.newInstance(client);
server.registerMBean(m, null);
}
try {
// forces check for dynamically created mbeans
server.queryNames(null, null);
} catch (IllegalStateException e) {
// ignore this. Just means we started before scylla.
}
String jmxPort = System.getProperty("com.sun.management.jmxremote.port");
System.out.println("JMX is enabled to receive remote connections on port: " + jmxPort);
for (;;) {
Thread.sleep(Long.MAX_VALUE);
}
}
示例11: getNewSourceRanges
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
/**
* Finds living endpoints responsible for the given ranges
*
* @param keyspaceName the keyspace ranges belong to
* @param ranges the ranges to find sources for
* @return multimap of addresses to ranges the address is responsible for
*/
private Multimap<InetAddress, Range<Token>> getNewSourceRanges(String keyspaceName, Set<Range<Token>> ranges)
{
InetAddress myAddress = FBUtilities.getBroadcastAddress();
Multimap<Range<Token>, InetAddress> rangeAddresses = Keyspace.open(keyspaceName).getReplicationStrategy().getRangeAddresses(tokenMetadata.cloneOnlyTokenMap());
Multimap<InetAddress, Range<Token>> sourceRanges = HashMultimap.create();
IFailureDetector failureDetector = FailureDetector.instance;
// find alive sources for our new ranges
for (Range<Token> range : ranges)
{
Collection<InetAddress> possibleRanges = rangeAddresses.get(range);
IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
List<InetAddress> sources = snitch.getSortedListByProximity(myAddress, possibleRanges);
assert (!sources.contains(myAddress));
for (InetAddress source : sources)
{
if (failureDetector.isAlive(source))
{
sourceRanges.put(source, range);
break;
}
}
}
return sourceRanges;
}
示例12: getLiveNaturalEndpoints
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
public List<InetAddress> getLiveNaturalEndpoints(Keyspace keyspace, RingPosition pos)
{
List<InetAddress> endpoints = keyspace.getReplicationStrategy().getNaturalEndpoints(pos);
List<InetAddress> liveEps = new ArrayList<>(endpoints.size());
for (InetAddress endpoint : endpoints)
{
if (FailureDetector.instance.isAlive(endpoint))
liveEps.add(endpoint);
}
return liveEps;
}
示例13: streamHints
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
private Future<StreamState> streamHints()
{
// StreamPlan will not fail if there are zero files to transfer, so flush anyway (need to get any in-memory hints, as well)
ColumnFamilyStore hintsCF = Keyspace.open(Keyspace.SYSTEM_KS).getColumnFamilyStore(SystemKeyspace.HINTS_CF);
FBUtilities.waitOnFuture(hintsCF.forceFlush());
// gather all live nodes in the cluster that aren't also leaving
List<InetAddress> candidates = new ArrayList<>(StorageService.instance.getTokenMetadata().cloneAfterAllLeft().getAllEndpoints());
candidates.remove(FBUtilities.getBroadcastAddress());
for (Iterator<InetAddress> iter = candidates.iterator(); iter.hasNext(); )
{
InetAddress address = iter.next();
if (!FailureDetector.instance.isAlive(address))
iter.remove();
}
if (candidates.isEmpty())
{
logger.warn("Unable to stream hints since no live endpoints seen");
return Futures.immediateFuture(null);
}
else
{
// stream to the closest peer as chosen by the snitch
DatabaseDescriptor.getEndpointSnitch().sortByProximity(FBUtilities.getBroadcastAddress(), candidates);
InetAddress hintsDestinationHost = candidates.get(0);
InetAddress preferred = SystemKeyspace.getPreferredIP(hintsDestinationHost);
// stream all hints -- range list will be a singleton of "the entire ring"
Token token = StorageService.getPartitioner().getMinimumToken();
List<Range<Token>> ranges = Collections.singletonList(new Range<>(token, token));
return new StreamPlan("Hints").transferRanges(hintsDestinationHost,
preferred,
Keyspace.SYSTEM_KS,
ranges,
SystemKeyspace.HINTS_CF)
.execute();
}
}
示例14: commitPaxos
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
private static void commitPaxos(Commit proposal, ConsistencyLevel consistencyLevel) throws WriteTimeoutException
{
boolean shouldBlock = consistencyLevel != ConsistencyLevel.ANY;
Keyspace keyspace = Keyspace.open(proposal.update.metadata().ksName);
Token tk = StorageService.getPartitioner().getToken(proposal.key);
List<InetAddress> naturalEndpoints = StorageService.instance.getNaturalEndpoints(keyspace.getName(), tk);
Collection<InetAddress> pendingEndpoints = StorageService.instance.getTokenMetadata().pendingEndpointsFor(tk, keyspace.getName());
AbstractWriteResponseHandler responseHandler = null;
if (shouldBlock)
{
AbstractReplicationStrategy rs = keyspace.getReplicationStrategy();
responseHandler = rs.getWriteResponseHandler(naturalEndpoints, pendingEndpoints, consistencyLevel, null, WriteType.SIMPLE);
}
MessageOut<Commit> message = new MessageOut<Commit>(MessagingService.Verb.PAXOS_COMMIT, proposal, Commit.serializer);
for (InetAddress destination : Iterables.concat(naturalEndpoints, pendingEndpoints))
{
if (FailureDetector.instance.isAlive(destination))
{
if (shouldBlock)
MessagingService.instance().sendRR(message, destination, responseHandler);
else
MessagingService.instance().sendOneWay(message, destination);
}
}
if (shouldBlock)
responseHandler.get();
}
示例15: deliverHintsToEndpoint
import org.apache.cassandra.gms.FailureDetector; //导入依赖的package包/类
private void deliverHintsToEndpoint(InetAddress endpoint)
{
if (hintStore.isEmpty())
return; // nothing to do, don't confuse users by logging a no-op handoff
// check if hints delivery has been paused
if (hintedHandOffPaused)
{
logger.debug("Hints delivery process is paused, aborting");
return;
}
logger.debug("Checking remote({}) schema before delivering hints", endpoint);
try
{
waitForSchemaAgreement(endpoint);
}
catch (TimeoutException e)
{
return;
}
if (!FailureDetector.instance.isAlive(endpoint))
{
logger.debug("Endpoint {} died before hint delivery, aborting", endpoint);
return;
}
doDeliverHintsToEndpoint(endpoint);
}