use of org.apache.geode.cache.persistence.RevokedPersistentDataException in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testRevokedMemberRedundancy0.
/**
* Test to make sure that we recreate a bucket if a member is revoked
*/
@Test
public void testRevokedMemberRedundancy0() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
createPR(vm0, 0);
createPR(vm1, 0);
createData(vm0, 0, NUM_BUCKETS, "a");
Set<Integer> vm0Buckets = getBucketList(vm0);
Set<Integer> vm1Buckets = getBucketList(vm1);
int aVM0Bucket = vm0Buckets.iterator().next();
int aVM1Bucket = vm1Buckets.iterator().next();
closeCache(vm1);
// This should work, because this bucket is still available.
checkData(vm0, aVM0Bucket, aVM0Bucket + 1, "a");
IgnoredException expect = IgnoredException.addIgnoredException("PartitionOfflineException", vm0);
try {
checkData(vm0, aVM1Bucket, aVM1Bucket + 1, "a");
fail("Should not have been able to read from missing buckets!");
} catch (RMIException e) {
if (!(e.getCause() instanceof PartitionOfflineException)) {
throw e;
}
}
try {
createData(vm0, aVM1Bucket, aVM1Bucket + 1, "b");
fail("Should not have been able to write to missing buckets!");
} catch (RMIException e) {
// We expect to see a partition offline exception here.
if (!(e.getCause() instanceof PartitionOfflineException)) {
throw e;
}
}
expect.remove();
// This should work, because these are new buckets
createData(vm0, NUM_BUCKETS, 113, "a");
revokeKnownMissingMembers(vm2, 1);
createPR(vm2, 0);
// We should be able to use that missing bucket now
checkData(vm2, aVM1Bucket, aVM1Bucket + 1, null);
createData(vm2, aVM1Bucket, aVM1Bucket + 1, "a");
checkData(vm2, aVM1Bucket, aVM1Bucket + 1, "a");
IgnoredException ex = IgnoredException.addIgnoredException(RevokedPersistentDataException.class.getName(), vm1);
try {
createPR(vm1, 0);
fail("Should have recieved a RevokedPersistentDataException");
} catch (RMIException e) {
// We revoked this member.
if (!(e.getCause() instanceof RevokedPersistentDataException)) {
throw e;
}
}
ex.remove();
}
use of org.apache.geode.cache.persistence.RevokedPersistentDataException in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testRevokeAfterStartup.
@Test
public void testRevokeAfterStartup() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
int numBuckets = 50;
createPR(vm0, 1);
createPR(vm1, 1);
createData(vm0, 0, numBuckets, "a");
Set<Integer> vm0Buckets = getBucketList(vm0);
Set<Integer> vm1Buckets = getBucketList(vm1);
assertEquals(vm0Buckets, vm1Buckets);
closeCache(vm0);
createData(vm1, 0, numBuckets, "b");
closeCache(vm1);
AsyncInvocation a1 = createPRAsync(vm0, 1);
// [dsmith] Make sure that vm0 is waiting for vm1 to recover
// If VM(0) recovers early, that is a problem, because vm1
// has newer data
Thread.sleep(500);
assertTrue(a1.isAlive());
revokeKnownMissingMembers(vm2, 1);
a1.getResult(MAX_WAIT);
assertEquals(vm0Buckets, getBucketList(vm0));
checkData(vm0, 0, numBuckets, "a");
createData(vm0, numBuckets, 113, "b");
checkData(vm0, numBuckets, 113, "b");
IgnoredException ex = IgnoredException.addIgnoredException(RevokedPersistentDataException.class.getName(), vm1);
try {
createPR(vm1, 1);
fail("Should have recieved a SplitDistributedSystemException");
} catch (RMIException e) {
// We revoked this member.
if (!(e.getCause() instanceof RevokedPersistentDataException)) {
throw e;
}
}
ex.remove();
}
use of org.apache.geode.cache.persistence.RevokedPersistentDataException in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testRevokeAHostBeforeInitialization.
/**
* Tests to make sure that we can revoke a member before initialization, and that member will stay
* revoked
*
* @throws Exception
*/
@Test
public void testRevokeAHostBeforeInitialization() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
LogWriterUtils.getLogWriter().info("Creating region in VM0");
createPersistentRegion(vm0);
LogWriterUtils.getLogWriter().info("Creating region in VM1");
createPersistentRegion(vm1);
putAnEntry(vm0);
vm0.invoke(new SerializableRunnable("Check for waiting regions") {
public void run() {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
PersistentMemberManager mm = cache.getPersistentMemberManager();
Map<String, Set<PersistentMemberID>> waitingRegions = mm.getWaitingRegions();
assertEquals(0, waitingRegions.size());
}
});
LogWriterUtils.getLogWriter().info("closing region in vm0");
closeRegion(vm0);
updateTheEntry(vm1);
LogWriterUtils.getLogWriter().info("closing region in vm1");
closeRegion(vm1);
final File dirToRevoke = getDiskDirForVM(vm1);
vm2.invoke(new SerializableRunnable("Revoke the member") {
public void run() {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
DistributedSystemConfig config;
AdminDistributedSystem adminDS = null;
try {
config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
adminDS.connect();
adminDS.revokePersistentMember(InetAddress.getLocalHost(), dirToRevoke.getCanonicalPath());
} catch (Exception e) {
Assert.fail("Unexpected exception", e);
} finally {
if (adminDS != null) {
adminDS.disconnect();
}
}
}
});
// This shouldn't wait, because we revoked the member
LogWriterUtils.getLogWriter().info("Creating region in VM0");
createPersistentRegion(vm0);
checkForRecoveryStat(vm0, true);
// Check to make sure we recovered the old
// value of the entry.
SerializableRunnable checkForEntry = new SerializableRunnable("check for the entry") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
assertEquals("B", region.get("A"));
}
};
vm0.invoke(checkForEntry);
// Now, we should not be able to create a region
// in vm1, because the this member was revoked
LogWriterUtils.getLogWriter().info("Creating region in VM1");
IgnoredException e = IgnoredException.addIgnoredException(RevokedPersistentDataException.class.getSimpleName(), vm1);
try {
createPersistentRegion(vm1);
fail("We should have received a split distributed system exception");
} catch (RuntimeException expected) {
if (!(expected.getCause() instanceof RevokedPersistentDataException)) {
throw expected;
}
// Do nothing
} finally {
e.remove();
}
}
use of org.apache.geode.cache.persistence.RevokedPersistentDataException in project geode by apache.
the class PersistenceAdvisorImpl method getMembersToWaitFor.
/**
* @param previouslyOnlineMembers the members we have persisted online in our persistence files
* @param offlineMembers This method will populate this set with any members that we are waiting
* for an are actually not running right now. This is different that the set of members we
* need to wait for - this member may end up waiting on member that is actually running.
* @return the list of members that this member needs to wait for before it can initialize.
*/
public Set<PersistentMemberID> getMembersToWaitFor(Set<PersistentMemberID> previouslyOnlineMembers, Set<PersistentMemberID> offlineMembers) throws ReplyException, InterruptedException {
PersistentMemberID myPersistentID = getPersistentID();
PersistentMemberID myInitializingId = getInitializingID();
// This is the set of members that are currently waiting for this member
// to come online.
Set<PersistentMemberID> membersToWaitFor = new HashSet<PersistentMemberID>(previouslyOnlineMembers);
offlineMembers.addAll(previouslyOnlineMembers);
// If our persistent ID is null, we need to wait for all of the previously online members.
if (myPersistentID != null || myInitializingId != null) {
Set<InternalDistributedMember> members = advisor.adviseProfileUpdate();
Set<InternalDistributedMember> membersHostingThisRegion = advisor.adviseGeneric();
// Fetch the persistent view from all of our peers.
PersistentStateQueryResults results = PersistentStateQueryMessage.send(members, advisor.getDistributionManager(), regionPath, myPersistentID, myInitializingId);
// iterate through all of the peers. For each peer:
// if the guy was previously online according to us, grab it's online
// members and add them to the members to wait for set.
// We may need to do this several times until we discover all of the
// members that may have newer data than
// us,
boolean addedMembers = true;
while (addedMembers) {
addedMembers = false;
for (Entry<InternalDistributedMember, Set<PersistentMemberID>> entry : results.onlineMemberMap.entrySet()) {
InternalDistributedMember memberId = entry.getKey();
Set<PersistentMemberID> peersOnlineMembers = entry.getValue();
PersistentMemberID persistentID = results.persistentIds.get(memberId);
PersistentMemberID initializingID = results.initializingIds.get(memberId);
if (membersToWaitFor.contains(persistentID) || membersToWaitFor.contains(initializingID)) {
for (PersistentMemberID peerOnlineMember : peersOnlineMembers) {
if (!isRevoked(peerOnlineMember) && !peerOnlineMember.diskStoreId.equals(getDiskStoreID()) && !storage.getOfflineMembers().contains(peerOnlineMember)) {
if (membersToWaitFor.add(peerOnlineMember)) {
addedMembers = true;
// Make sure we also persist that this member is online.
storage.memberOnline(peerOnlineMember);
if (logger.isDebugEnabled(LogMarker.PERSIST_ADVISOR)) {
logger.debug(LogMarker.PERSIST_ADVISOR, "{}-{}: Adding {} to the list of members we're wait for, because {} has newer or equal data than is and is waiting for that member", shortDiskStoreId(), regionPath, peerOnlineMember, memberId);
}
}
}
}
}
}
}
if (logger.isDebugEnabled(LogMarker.PERSIST_ADVISOR)) {
logger.debug(LogMarker.PERSIST_ADVISOR, "{}-{}: Initial state of membersToWaitFor, before pruning {}", shortDiskStoreId(), regionPath, membersToWaitFor);
}
// For each of our peers, see what our state is according to their view.
for (Map.Entry<InternalDistributedMember, PersistentMemberState> entry : results.stateOnPeers.entrySet()) {
InternalDistributedMember memberId = entry.getKey();
PersistentMemberID persistentID = results.persistentIds.get(memberId);
PersistentMemberID initializingID = results.initializingIds.get(memberId);
DiskStoreID diskStoreID = results.diskStoreIds.get(memberId);
PersistentMemberState state = entry.getValue();
if (PersistentMemberState.REVOKED.equals(state)) {
throw new RevokedPersistentDataException(LocalizedStrings.PersistentMemberManager_Member_0_is_already_revoked.toLocalizedString(myPersistentID));
}
// need to wait for this peer.
if (membersHostingThisRegion.contains(memberId) && persistentID != null && state != null && myInitializingId == null && (state.equals(PersistentMemberState.ONLINE) || state.equals(PersistentMemberState.EQUAL))) {
if (logger.isDebugEnabled(LogMarker.PERSIST_ADVISOR)) {
logger.debug(LogMarker.PERSIST_ADVISOR, "{}-{}: Not waiting for {} because it thinks our state was {}", shortDiskStoreId(), regionPath, persistentID, state);
}
removeNewerPersistentID(membersToWaitFor, persistentID);
}
// If the peer has an initialized ID, they are no longer offline.
if (persistentID != null) {
removeNewerPersistentID(offlineMembers, persistentID);
}
// need to wait for this peer.
if (membersHostingThisRegion.contains(memberId) && initializingID != null && state != null && (state.equals(PersistentMemberState.ONLINE) || state.equals(PersistentMemberState.EQUAL))) {
if (logger.isDebugEnabled(LogMarker.PERSIST_ADVISOR)) {
logger.debug(LogMarker.PERSIST_ADVISOR, "{}-{}: Not waiting for {} because it thinks our state was {}", shortDiskStoreId(), regionPath, initializingID, state);
}
removeNewerPersistentID(membersToWaitFor, initializingID);
}
// If the peer has an initializing id, they are also not online.
if (initializingID != null) {
removeNewerPersistentID(offlineMembers, initializingID);
}
// we should be waiting for it, stop waiting for it.
if (initializingID == null && persistentID == null & diskStoreID != null) {
removeByDiskStoreID(membersToWaitFor, diskStoreID);
removeByDiskStoreID(offlineMembers, diskStoreID);
}
}
}
return membersToWaitFor;
}
use of org.apache.geode.cache.persistence.RevokedPersistentDataException in project geode by apache.
the class PersistenceAdvisorImpl method checkMyStateOnMembers.
public boolean checkMyStateOnMembers(Set<InternalDistributedMember> replicates) throws ReplyException {
PersistentStateQueryResults remoteStates = getMyStateOnMembers(replicates);
boolean equal = false;
if (observer != null) {
observer.observe(regionPath);
}
for (Map.Entry<InternalDistributedMember, PersistentMemberState> entry : remoteStates.stateOnPeers.entrySet()) {
InternalDistributedMember member = entry.getKey();
PersistentMemberID remoteId = remoteStates.persistentIds.get(member);
final PersistentMemberID myId = getPersistentID();
PersistentMemberState stateOnPeer = entry.getValue();
if (PersistentMemberState.REVOKED.equals(stateOnPeer)) {
throw new RevokedPersistentDataException(LocalizedStrings.PersistentMemberManager_Member_0_is_already_revoked.toLocalizedString(myId));
}
if (myId != null && stateOnPeer == null) {
String message = LocalizedStrings.CreatePersistentRegionProcessor_SPLIT_DISTRIBUTED_SYSTEM.toLocalizedString(regionPath, member, remoteId, myId);
throw new ConflictingPersistentDataException(message);
}
if (myId != null && stateOnPeer == PersistentMemberState.EQUAL) {
equal = true;
}
// comes back online.
if (remoteId != null) {
PersistentMemberState remoteState = getPersistedStateOfMember(remoteId);
if (remoteState == PersistentMemberState.OFFLINE) {
String message = LocalizedStrings.CreatePersistentRegionProcessor_INITIALIZING_FROM_OLD_DATA.toLocalizedString(regionPath, member, remoteId, myId);
throw new ConflictingPersistentDataException(message);
}
}
}
return equal;
}
Aggregations