本文整理汇总了Java中org.apache.cassandra.utils.FBUtilities.getBroadcastAddress方法的典型用法代码示例。如果您正苦于以下问题:Java FBUtilities.getBroadcastAddress方法的具体用法?Java FBUtilities.getBroadcastAddress怎么用?Java FBUtilities.getBroadcastAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.cassandra.utils.FBUtilities
的用法示例。
在下文中一共展示了FBUtilities.getBroadcastAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startSync
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
/**
* Starts sending/receiving our list of differences to/from the remote endpoint: creates a callback
* that will be called out of band once the streams complete.
*/
protected void startSync(List<Range<Token>> differences)
{
InetAddress local = FBUtilities.getBroadcastAddress();
// We can take anyone of the node as source or destination, however if one is localhost, we put at source to avoid a forwarding
InetAddress dst = r2.endpoint.equals(local) ? r1.endpoint : r2.endpoint;
InetAddress preferred = SystemKeyspace.getPreferredIP(dst);
String message = String.format("Performing streaming repair of %d ranges with %s", differences.size(), dst);
logger.info("[repair #{}] {}", desc.sessionId, message);
boolean isIncremental = false;
if (desc.parentSessionId != null)
{
ActiveRepairService.ParentRepairSession prs = ActiveRepairService.instance.getParentRepairSession(desc.parentSessionId);
isIncremental = prs.isIncremental;
}
Tracing.traceRepair(message);
new StreamPlan("Repair", repairedAt, 1, false, isIncremental).listeners(this)
.flushBeforeTransfer(true)
// request ranges from the remote node
.requestRanges(dst, preferred, desc.keyspace, differences, desc.columnFamily)
// send ranges to the remote node
.transferRanges(dst, preferred, desc.keyspace, differences, desc.columnFamily)
.execute();
}
示例2: testValidationCompleteWrite
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
private void testValidationCompleteWrite() throws IOException
{
IPartitioner p = RandomPartitioner.instance;
MerkleTrees mt = new MerkleTrees(p);
// empty validation
mt.addMerkleTree((int) Math.pow(2, 15), FULL_RANGE);
Validator v0 = new Validator(DESC, FBUtilities.getBroadcastAddress(), -1);
ValidationComplete c0 = new ValidationComplete(DESC, mt);
// validation with a tree
mt = new MerkleTrees(p);
mt.addMerkleTree(Integer.MAX_VALUE, FULL_RANGE);
for (int i = 0; i < 10; i++)
mt.split(p.getRandomToken());
Validator v1 = new Validator(DESC, FBUtilities.getBroadcastAddress(), -1);
ValidationComplete c1 = new ValidationComplete(DESC, mt);
// validation failed
ValidationComplete c3 = new ValidationComplete(DESC);
testRepairMessageWrite("service.ValidationComplete.bin", c0, c1, c3);
}
示例3: getNewSourceRanges
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的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;
}
示例4: testAllocateTokens
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Test
public void testAllocateTokens() throws UnknownHostException
{
int vn = 16;
String ks = "BootStrapperTestKeyspace3";
TokenMetadata tm = new TokenMetadata();
generateFakeEndpoints(tm, 10, vn);
InetAddress addr = FBUtilities.getBroadcastAddress();
allocateTokensForNode(vn, ks, tm, addr);
}
示例5: performStreamingRepair
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
/**
* Starts sending/receiving our list of differences to/from the remote endpoint: creates a callback
* that will be called out of band once the streams complete.
*/
void performStreamingRepair()
{
InetAddress local = FBUtilities.getBroadcastAddress();
// We can take anyone of the node as source or destination, however if one is localhost, we put at source to avoid a forwarding
InetAddress src = r2.endpoint.equals(local) ? r2.endpoint : r1.endpoint;
InetAddress dst = r2.endpoint.equals(local) ? r1.endpoint : r2.endpoint;
SyncRequest request = new SyncRequest(desc, local, src, dst, differences);
StreamingRepairTask task = new StreamingRepairTask(desc, request);
task.run();
}
示例6: sendInitMessage
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
public void sendInitMessage(Socket socket, boolean isForOutgoing) throws IOException
{
StreamInitMessage message = new StreamInitMessage(
FBUtilities.getBroadcastAddress(),
session.sessionIndex(),
session.planId(),
session.description(),
isForOutgoing);
ByteBuffer messageBuf = message.createMessage(false, protocolVersion);
getWriteChannel(socket).write(messageBuf);
}
示例7: resetGcGraceSeconds
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Before
public void resetGcGraceSeconds()
{
TokenMetadata tokenMeta = StorageService.instance.getTokenMetadata();
InetAddress local = FBUtilities.getBroadcastAddress();
tokenMeta.clearUnsafe();
tokenMeta.updateHostId(UUID.randomUUID(), local);
tokenMeta.updateNormalTokens(BootStrapper.getRandomTokens(tokenMeta, 1), local);
for (CFMetaData table : Schema.instance.getTablesAndViews(KEYSPACE))
table.gcGraceSeconds(TableParams.DEFAULT_GC_GRACE_SECONDS);
}
示例8: testValidationMultipleSSTablePerLevel
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Test
public void testValidationMultipleSSTablePerLevel() throws Exception
{
byte [] b = new byte[100 * 1024];
new Random().nextBytes(b);
ByteBuffer value = ByteBuffer.wrap(b); // 100 KB value, make it easy to have multiple files
// Enough data to have a level 1 and 2
int rows = 40;
int columns = 20;
// Adds enough data to trigger multiple sstable per level
for (int r = 0; r < rows; r++)
{
UpdateBuilder update = UpdateBuilder.create(cfs.metadata, String.valueOf(r));
for (int c = 0; c < columns; c++)
update.newRow("column" + c).add("val", value);
update.applyUnsafe();
cfs.forceBlockingFlush();
}
waitForLeveling(cfs);
CompactionStrategyManager strategy = cfs.getCompactionStrategyManager();
// Checking we're not completely bad at math
assertTrue(strategy.getSSTableCountPerLevel()[1] > 0);
assertTrue(strategy.getSSTableCountPerLevel()[2] > 0);
Range<Token> range = new Range<>(Util.token(""), Util.token(""));
int gcBefore = keyspace.getColumnFamilyStore(CF_STANDARDDLEVELED).gcBefore(FBUtilities.nowInSeconds());
UUID parentRepSession = UUID.randomUUID();
ActiveRepairService.instance.registerParentRepairSession(parentRepSession, FBUtilities.getBroadcastAddress(), Arrays.asList(cfs), Arrays.asList(range), false, System.currentTimeMillis(), true);
RepairJobDesc desc = new RepairJobDesc(parentRepSession, UUID.randomUUID(), KEYSPACE1, CF_STANDARDDLEVELED, Arrays.asList(range));
Validator validator = new Validator(desc, FBUtilities.getBroadcastAddress(), gcBefore);
CompactionManager.instance.submitValidation(cfs, validator).get();
}
示例9: testAllocateTokensMultipleKeyspaces
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Test
public void testAllocateTokensMultipleKeyspaces() throws UnknownHostException
{
// TODO: This scenario isn't supported very well. Investigate a multi-keyspace version of the algorithm.
int vn = 16;
String ks3 = "BootStrapperTestKeyspace4"; // RF = 3
String ks2 = "BootStrapperTestKeyspace5"; // RF = 2
TokenMetadata tm = new TokenMetadata();
generateFakeEndpoints(tm, 10, vn);
InetAddress dcaddr = FBUtilities.getBroadcastAddress();
SummaryStatistics os3 = TokenAllocation.replicatedOwnershipStats(tm, Keyspace.open(ks3).getReplicationStrategy(), dcaddr);
SummaryStatistics os2 = TokenAllocation.replicatedOwnershipStats(tm, Keyspace.open(ks2).getReplicationStrategy(), dcaddr);
String cks = ks3;
String nks = ks2;
for (int i=11; i<=20; ++i)
{
allocateTokensForNode(vn, cks, tm, InetAddress.getByName("127.0.0." + (i + 1)));
String t = cks; cks = nks; nks = t;
}
SummaryStatistics ns3 = TokenAllocation.replicatedOwnershipStats(tm, Keyspace.open(ks3).getReplicationStrategy(), dcaddr);
SummaryStatistics ns2 = TokenAllocation.replicatedOwnershipStats(tm, Keyspace.open(ks2).getReplicationStrategy(), dcaddr);
verifyImprovement(os3, ns3);
verifyImprovement(os2, ns2);
}
示例10: removeNode
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
/**
* Remove a node that has died, attempting to restore the replica count.
* If the node is alive, decommission should be attempted. If decommission
* fails, then removeToken should be called. If we fail while trying to
* restore the replica count, finally forceRemoveCompleteion should be
* called to forcibly remove the node without regard to replica count.
*
* @param hostIdString token for the node
*/
public void removeNode(String hostIdString)
{
InetAddress myAddress = FBUtilities.getBroadcastAddress();
UUID localHostId = tokenMetadata.getHostId(myAddress);
UUID hostId = UUID.fromString(hostIdString);
InetAddress endpoint = tokenMetadata.getEndpointForHostId(hostId);
if (endpoint == null)
throw new UnsupportedOperationException("Host ID not found.");
Collection<Token> tokens = tokenMetadata.getTokens(endpoint);
if (endpoint.equals(myAddress))
throw new UnsupportedOperationException("Cannot remove self");
if (Gossiper.instance.getLiveMembers().contains(endpoint))
throw new UnsupportedOperationException("Node " + endpoint + " is alive and owns this ID. Use decommission command to remove it from the ring");
// A leaving endpoint that is dead is already being removed.
if (tokenMetadata.isLeaving(endpoint))
logger.warn("Node {} is already being removed, continuing removal anyway", endpoint);
if (!replicatingNodes.isEmpty())
throw new UnsupportedOperationException("This node is already processing a removal. Wait for it to complete, or use 'removenode force' if this has failed.");
// Find the endpoints that are going to become responsible for data
for (String keyspaceName : Schema.instance.getNonSystemKeyspaces())
{
// if the replication factor is 1 the data is lost so we shouldn't wait for confirmation
if (Keyspace.open(keyspaceName).getReplicationStrategy().getReplicationFactor() == 1)
continue;
// get all ranges that change ownership (that is, a node needs
// to take responsibility for new range)
Multimap<Range<Token>, InetAddress> changedRanges = getChangedRangesForLeaving(keyspaceName, endpoint);
IFailureDetector failureDetector = FailureDetector.instance;
for (InetAddress ep : changedRanges.values())
{
if (failureDetector.isAlive(ep))
replicatingNodes.add(ep);
else
logger.warn("Endpoint {} is down and will not receive data for re-replication of {}", ep, endpoint);
}
}
removingNode = endpoint;
tokenMetadata.addLeavingEndpoint(endpoint);
PendingRangeCalculatorService.instance.update();
// the gossiper will handle spoofing this node's state to REMOVING_TOKEN for us
// we add our own token so other nodes to let us know when they're done
Gossiper.instance.advertiseRemoving(endpoint, hostId, localHostId);
// kick off streaming commands
restoreReplicaCount(endpoint, myAddress);
// wait for ReplicationFinishedVerbHandler to signal we're done
while (!replicatingNodes.isEmpty())
{
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
}
excise(tokens, endpoint);
// gossiper will indicate the token has left
Gossiper.instance.advertiseTokenRemoved(endpoint, hostId);
replicatingNodes.clear();
removingNode = null;
}
示例11: ExpiredTraceState
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
public ExpiredTraceState(UUID sessionId)
{
super(FBUtilities.getBroadcastAddress(), sessionId);
}
示例12: MessageOut
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
private MessageOut(MessagingService.Verb verb, T payload, IVersionedSerializer<T> serializer, Map<String, byte[]> parameters)
{
this(FBUtilities.getBroadcastAddress(), verb, payload, serializer, parameters);
}
示例13: testSnitch
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Test
public void testSnitch() throws InterruptedException, IOException, ConfigurationException
{
// do this because SS needs to be initialized before DES can work properly.
StorageService.instance.initClient(0);
SimpleSnitch ss = new SimpleSnitch();
DynamicEndpointSnitch dsnitch = new DynamicEndpointSnitch(ss, String.valueOf(ss.hashCode()));
InetAddress self = FBUtilities.getBroadcastAddress();
InetAddress host1 = InetAddress.getByName("127.0.0.2");
InetAddress host2 = InetAddress.getByName("127.0.0.3");
InetAddress host3 = InetAddress.getByName("127.0.0.4");
List<InetAddress> hosts = Arrays.asList(host1, host2, host3);
// first, make all hosts equal
setScores(dsnitch, 1, hosts, 10, 10, 10);
List<InetAddress> order = Arrays.asList(host1, host2, host3);
assertEquals(order, dsnitch.getSortedListByProximity(self, Arrays.asList(host1, host2, host3)));
// make host1 a little worse
setScores(dsnitch, 1, hosts, 20, 10, 10);
order = Arrays.asList(host2, host3, host1);
assertEquals(order, dsnitch.getSortedListByProximity(self, Arrays.asList(host1, host2, host3)));
// make host2 as bad as host1
setScores(dsnitch, 2, hosts, 15, 20, 10);
order = Arrays.asList(host3, host1, host2);
assertEquals(order, dsnitch.getSortedListByProximity(self, Arrays.asList(host1, host2, host3)));
// make host3 the worst
setScores(dsnitch, 3, hosts, 10, 10, 30);
order = Arrays.asList(host1, host2, host3);
assertEquals(order, dsnitch.getSortedListByProximity(self, Arrays.asList(host1, host2, host3)));
// make host3 equal to the others
setScores(dsnitch, 5, hosts, 10, 10, 10);
order = Arrays.asList(host1, host2, host3);
assertEquals(order, dsnitch.getSortedListByProximity(self, Arrays.asList(host1, host2, host3)));
/// Tests CASSANDRA-6683 improvements
// make the scores differ enough from the ideal order that we sort by score; under the old
// dynamic snitch behavior (where we only compared neighbors), these wouldn't get sorted
setScores(dsnitch, 20, hosts, 10, 70, 20);
order = Arrays.asList(host1, host3, host2);
assertEquals(order, dsnitch.getSortedListByProximity(self, Arrays.asList(host1, host2, host3)));
}
示例14: testScheduleTimeout
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Test
public void testScheduleTimeout() throws Exception
{
String ks = "Keyspace1";
String cf = "Standard1";
InetAddress peer = FBUtilities.getBroadcastAddress();
StreamSession session = new StreamSession(peer, peer, null, 0);
ColumnFamilyStore cfs = Keyspace.open(ks).getColumnFamilyStore(cf);
// create two sstables
for (int i = 0; i < 2; i++)
{
insertData(ks, cf, i, 1);
cfs.forceBlockingFlush();
}
// create streaming task that streams those two sstables
StreamTransferTask task = new StreamTransferTask(session, cfs.metadata.cfId);
for (SSTableReader sstable : cfs.getSSTables())
{
List<Range<Token>> ranges = new ArrayList<>();
ranges.add(new Range<>(sstable.first.getToken(), sstable.last.getToken()));
task.addTransferFile(sstable, sstable.selfRef(), 1, sstable.getPositionsForRanges(ranges), 0);
}
assertEquals(2, task.getTotalNumberOfFiles());
// if file sending completes before timeout then the task should be canceled.
Future f = task.scheduleTimeout(0, 0, TimeUnit.NANOSECONDS);
f.get();
// when timeout runs on second file, task should be completed
f = task.scheduleTimeout(1, 1, TimeUnit.MILLISECONDS);
task.complete(1);
try
{
f.get();
Assert.assertTrue(false);
}
catch (CancellationException ex)
{
}
assertEquals(StreamSession.State.WAIT_COMPLETE, session.state());
// when all streaming are done, time out task should not be scheduled.
assertNull(task.scheduleTimeout(1, 1, TimeUnit.SECONDS));
}
示例15: sendInitMessage
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
public void sendInitMessage(boolean isForOutgoing) throws IOException
{
StreamInitMessage message = new StreamInitMessage(FBUtilities.getBroadcastAddress(), session.planId(), session.description(), isForOutgoing);
getWriteChannel().write(message.createMessage(false, protocolVersion));
}