use of org.apache.cassandra.service.StorageService in project cassandra by apache.
the class RangeTombstoneListTest method testSetInitialAllocationSize.
@Test
public void testSetInitialAllocationSize() {
int original = DatabaseDescriptor.getInitialRangeTombstoneListAllocationSize();
final StorageService storageService = StorageService.instance;
final Consumer<Throwable> expectIllegalStateExceptio = exception -> {
assertSame(String.format("The actual exception message:<%s>", exception.getMessage()), IllegalStateException.class, exception.getClass());
assertEquals("Not updating initial_range_tombstone_allocation_size as it must be in the range [0, 1024] inclusive", exception.getMessage());
};
try {
// prevent bad ones
assertHasException(() -> storageService.setInitialRangeTombstoneListAllocationSize(-1), expectIllegalStateExceptio);
assertHasException(() -> storageService.setInitialRangeTombstoneListAllocationSize(1025), expectIllegalStateExceptio);
// accept good ones
storageService.setInitialRangeTombstoneListAllocationSize(1);
storageService.setInitialRangeTombstoneListAllocationSize(1024);
} finally {
storageService.setInitialRangeTombstoneListAllocationSize(original);
}
}
use of org.apache.cassandra.service.StorageService in project cassandra by apache.
the class GossipHelper method changeGossipState.
/**
* Changes gossip state of the `peer` on `target`
*/
public static void changeGossipState(IInvokableInstance target, IInstance peer, List<VersionedApplicationState> newState) {
InetSocketAddress addr = peer.broadcastAddress();
UUID hostId = peer.config().hostId();
int netVersion = peer.getMessagingVersion();
target.runOnInstance(() -> {
InetAddressAndPort endpoint = toCassandraInetAddressAndPort(addr);
StorageService storageService = StorageService.instance;
Gossiper.runInGossipStageBlocking(() -> {
EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
if (state == null) {
Gossiper.instance.initializeNodeUnsafe(endpoint, hostId, netVersion, 1);
state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
if (state.isAlive() && !Gossiper.instance.isDeadState(state))
Gossiper.instance.realMarkAlive(endpoint, state);
}
for (VersionedApplicationState value : newState) {
ApplicationState as = toApplicationState(value);
VersionedValue vv = toVersionedValue(value);
state.addApplicationState(as, vv);
storageService.onChange(endpoint, as, vv);
}
});
});
}
use of org.apache.cassandra.service.StorageService in project eiger by wlloyd.
the class BootStrapperTest method testMulitipleAutomaticBootstraps.
@Test
public void testMulitipleAutomaticBootstraps() throws IOException {
StorageService ss = StorageService.instance;
generateFakeEndpoints(5);
InetAddress[] addrs = new InetAddress[] { InetAddress.getByName("127.0.0.2"), InetAddress.getByName("127.0.0.3"), InetAddress.getByName("127.0.0.4"), InetAddress.getByName("127.0.0.5") };
InetAddress[] bootstrapAddrs = new InetAddress[] { InetAddress.getByName("127.0.0.12"), InetAddress.getByName("127.0.0.13"), InetAddress.getByName("127.0.0.14"), InetAddress.getByName("127.0.0.15") };
Map<InetAddress, Double> load = new HashMap<InetAddress, Double>();
for (int i = 0; i < addrs.length; i++) load.put(addrs[i], (double) i + 2);
// give every node a bootstrap source.
for (int i = 3; i >= 0; i--) {
InetAddress bootstrapSource = BootStrapper.getBootstrapSource(ss.getTokenMetadata(), load);
assert bootstrapSource != null;
assert bootstrapSource.equals(addrs[i]) : String.format("expected %s but got %s for %d", addrs[i], bootstrapSource, i);
assert !ss.getTokenMetadata().getBootstrapTokens().containsValue(bootstrapSource);
Range<Token> range = ss.getPrimaryRangeForEndpoint(bootstrapSource);
Token token = StorageService.getPartitioner().midpoint(range.left, range.right);
assert range.contains(token);
ss.onChange(bootstrapAddrs[i], ApplicationState.STATUS, StorageService.instance.valueFactory.bootstrapping(token));
}
// any further attempt to bootsrtap should fail since every node in the cluster is splitting.
try {
BootStrapper.getBootstrapSource(ss.getTokenMetadata(), load);
throw new AssertionError("This bootstrap should have failed.");
} catch (RuntimeException ex) {
// success!
}
// indicate that one of the nodes is done. see if the node it was bootstrapping from is still available.
Range<Token> range = ss.getPrimaryRangeForEndpoint(addrs[2]);
Token token = StorageService.getPartitioner().midpoint(range.left, range.right);
ss.onChange(bootstrapAddrs[2], ApplicationState.STATUS, StorageService.instance.valueFactory.normal(token));
load.put(bootstrapAddrs[2], 0d);
InetAddress addr = BootStrapper.getBootstrapSource(ss.getTokenMetadata(), load);
assert addr != null && addr.equals(addrs[2]);
}
use of org.apache.cassandra.service.StorageService in project eiger by wlloyd.
the class BootStrapperTest method testSourceTargetComputation.
private void testSourceTargetComputation(String table, int numOldNodes, int replicationFactor) throws UnknownHostException {
StorageService ss = StorageService.instance;
generateFakeEndpoints(numOldNodes);
Token myToken = StorageService.getPartitioner().getRandomToken();
InetAddress myEndpoint = InetAddress.getByName("127.0.0.1");
TokenMetadata tmd = ss.getTokenMetadata();
assertEquals(numOldNodes, tmd.sortedTokens().size());
BootStrapper b = new BootStrapper(myEndpoint, myToken, tmd);
Multimap<Range<Token>, InetAddress> res = b.getRangesWithSources(table);
int transferCount = 0;
for (Map.Entry<Range<Token>, Collection<InetAddress>> e : res.asMap().entrySet()) {
assert e.getValue() != null && e.getValue().size() > 0 : StringUtils.join(e.getValue(), ", ");
transferCount++;
}
assertEquals(replicationFactor, transferCount);
IFailureDetector mockFailureDetector = new IFailureDetector() {
public boolean isAlive(InetAddress ep) {
return true;
}
public void interpret(InetAddress ep) {
throw new UnsupportedOperationException();
}
public void report(InetAddress ep) {
throw new UnsupportedOperationException();
}
public void registerFailureDetectionEventListener(IFailureDetectionEventListener listener) {
throw new UnsupportedOperationException();
}
public void unregisterFailureDetectionEventListener(IFailureDetectionEventListener listener) {
throw new UnsupportedOperationException();
}
public void remove(InetAddress ep) {
throw new UnsupportedOperationException();
}
public void clear(InetAddress ep) {
throw new UnsupportedOperationException();
}
};
Multimap<InetAddress, Range<Token>> temp = BootStrapper.getWorkMap(res, mockFailureDetector);
// is used, they will vary.
assert temp.keySet().size() > 0;
assert temp.asMap().values().iterator().next().size() > 0;
assert !temp.keySet().iterator().next().equals(myEndpoint);
}
use of org.apache.cassandra.service.StorageService in project cassandra by apache.
the class RangeTombstoneListTest method testSetResizeFactor.
@Test
public void testSetResizeFactor() {
double original = DatabaseDescriptor.getRangeTombstoneListGrowthFactor();
final StorageService storageService = StorageService.instance;
final Consumer<Throwable> expectIllegalStateExceptio = exception -> {
assertSame(IllegalStateException.class, exception.getClass());
assertEquals("Not updating range_tombstone_resize_factor as growth factor must be in the range [1.2, 5.0] inclusive", exception.getMessage());
};
try {
// prevent bad ones
assertHasException(() -> storageService.setRangeTombstoneListResizeGrowthFactor(-1), expectIllegalStateExceptio);
assertHasException(() -> storageService.setRangeTombstoneListResizeGrowthFactor(0), expectIllegalStateExceptio);
assertHasException(() -> storageService.setRangeTombstoneListResizeGrowthFactor(1.1), expectIllegalStateExceptio);
assertHasException(() -> storageService.setRangeTombstoneListResizeGrowthFactor(5.1), expectIllegalStateExceptio);
// accept good ones
storageService.setRangeTombstoneListResizeGrowthFactor(1.2);
storageService.setRangeTombstoneListResizeGrowthFactor(2.0);
storageService.setRangeTombstoneListResizeGrowthFactor(5.0);
} finally {
storageService.setRangeTombstoneListResizeGrowthFactor(original);
}
}
Aggregations