Skip to content

Commit

Permalink
JBTM-3859 clear MBean cache before probing
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusgrov committed Nov 21, 2024
1 parent 021cf2e commit 347a0ef
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,34 +423,6 @@ public void setExposeAllRecordsAsMBeans(boolean exposeAllLogs) {
this.exposeAllLogs = exposeAllLogs;
}

/**
* Update registered MBeans based on the current set of Uids.
* @param allCurrUids any registered MBeans not in this collection will be deregistered
*/
private void unregisterRemovedUids(Map<String, Collection<Uid>> allCurrUids) {

for (Map.Entry<String, List<UidWrapper>> e : registeredMBeans.entrySet()) {
String type = e.getKey();
List<UidWrapper> registeredBeansOfType = e.getValue();
Collection<Uid> currUidsOfType = allCurrUids.get(type);

if (currUidsOfType != null) {
Iterator<UidWrapper> iterator = registeredBeansOfType.iterator();

while (iterator.hasNext()) {
UidWrapper w = iterator.next();

if (!currUidsOfType.contains(w.getUid())) {
w.unregister();
iterator.remove();
}
}
} else {
unregisterMBeans(registeredBeansOfType);
}
}
}

/**
* See if any new MBeans need to be registered or if any existing MBeans no longer exist
* as ObjectStore entries.
Expand All @@ -460,12 +432,12 @@ private void unregisterRemovedUids(Map<String, Collection<Uid>> allCurrUids) {
public synchronized void probe() throws MBeanException {
Map<String, Collection<Uid>> currUidsForType = new HashMap<>();

// recreate every MBean so clear the cache first
unregisterMBeans();

for (String type : getTypes())
currUidsForType.put(type, getUids(type));

// if there are any beans in registeredMBeans that don't appear in new list and unregister them
unregisterRemovedUids(currUidsForType); //unregisterMBeans();

for (Map.Entry<String, Collection<Uid>> e : currUidsForType.entrySet()) {
String type = e.getKey();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
import com.arjuna.ats.arjuna.coordinator.RecordType;
import com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeManager;
import com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap;
import com.arjuna.ats.arjuna.recovery.RecoveryDriver;
import com.arjuna.ats.arjuna.recovery.RecoveryManager;
import com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean;
import com.arjuna.ats.arjuna.tools.osb.mbean.LogRecordWrapper;
import com.arjuna.ats.arjuna.tools.osb.mbean.OSEntryBean;
Expand All @@ -51,6 +49,8 @@
import com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple;
import com.hp.mwtests.ts.arjuna.resources.CrashRecord;

import java.util.Collection;

/**
* @deprecated as of 5.0.5.Final In a subsequent release we will change packages names in order to
* provide a better separation between public and internal classes.
Expand Down Expand Up @@ -182,15 +182,8 @@ public void aaTest(boolean replay) throws Exception {
osb.start();
osb.probe();

// there should be one MBean corresponding to the AtomicAction A
UidWrapper w = osb.findUid(A.get_uid());
assertNotNull(w);
OSEntryBean ai = w.getMBean();
assertNotNull(ai);

// the MBean should wrap an ActionBean
assertTrue(ai instanceof ActionBean);
ActionBean actionBean = (ActionBean) ai;
// there should be one MBean corresponding to the AtomicAction A and the MBean should wrap an ActionBean
ActionBean actionBean = lookupActionBean(osb, A.get_uid());

// and there should be one MBean corresponding to the CrashRecord that got the heuristic:
int recCount = 0;
Expand All @@ -211,6 +204,16 @@ public void aaTest(boolean replay) throws Exception {

assertEquals(1, recCount);

// verify that the state on disk is no longer a heuristic
actionBean = lookupActionBean(osb, A.get_uid());
Collection<LogRecordWrapper> participants = actionBean.getParticipants();

// there should be only the heuristic participant remaining:
assertEquals(1, participants.size());
LogRecordWrapper wrapper = actionBean.getParticipants().iterator().next();
// and it should no longer be a heuristic
assertFalse(wrapper.isHeuristic());

if (!replay) {
actionBean.remove();
} else {
Expand All @@ -228,13 +231,21 @@ public void aaTest(boolean replay) throws Exception {
osb.probe();

// look up the MBean and verify that it no longer exists
w = osb.findUid(A.get_uid());
assertNull(w);
assertNull(osb.findUid(A.get_uid()));

osb.dump(new StringBuilder());
osb.stop();
}

private ActionBean lookupActionBean(ObjStoreBrowser osb, Uid uid) {
UidWrapper w = osb.findUid(uid);
assertNotNull(w);
OSEntryBean ai = w.getMBean();
assertNotNull(ai);
assertTrue(ai instanceof ActionBean);

return (ActionBean) ai;
}

// define an MBean interface for use in the next test
public interface NotAnotherMBean extends ObjStoreItemMBean {}

Expand Down

0 comments on commit 347a0ef

Please sign in to comment.