Skip to content
Permalink
Browse files
Fix static instance bug in DistViewAggregatorStateModel (#2124)
Change to use non-static reference in statemodel
  • Loading branch information
qqu0127 committed May 31, 2022
1 parent 1a1fe31 commit 5909a8a363499489d545ff4ddf8464140f56076c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
@@ -32,8 +32,7 @@
})
public class DistViewAggregatorStateModel extends AbstractHelixLeaderStandbyStateModel {
private final static Logger logger = LoggerFactory.getLogger(DistViewAggregatorStateModel.class);
private final static Object stateTransitionLock = new Object();
private static HelixViewAggregator _aggregator;
private HelixViewAggregator _aggregator;

public DistViewAggregatorStateModel(String zkAddr) {
super(zkAddr);
@@ -48,25 +47,22 @@ public void onBecomeStandbyFromOffline(Message message, NotificationContext cont
public void onBecomeLeaderFromStandby(Message message, NotificationContext context)
throws Exception {
String viewClusterName = message.getPartitionName();

synchronized (stateTransitionLock) {
if (_aggregator != null) {
logger.warn("Aggregator already exists for view cluster {}: {}: cleaning it up.",
viewClusterName, _aggregator.getAggregatorInstanceName());
reset();
}
logger.info("Creating new HelixViewAggregator for view cluster {}", viewClusterName);
try {
_aggregator = new HelixViewAggregator(viewClusterName, _zkAddr);
_aggregator.start();
} catch (Exception e) {
logger.error("Aggregator failed to become leader from stand by for view cluster {}",
viewClusterName, e);
reset();
throw e;
}
logStateTransition("STANDBY", "LEADER", message.getPartitionName(), message.getTgtName());
if (_aggregator != null) {
logger.warn("Aggregator already exists for view cluster {}: {}: cleaning it up.",
viewClusterName, _aggregator.getAggregatorInstanceName());
reset();
}
logger.info("Creating new HelixViewAggregator for view cluster {}", viewClusterName);
try {
_aggregator = new HelixViewAggregator(viewClusterName, _zkAddr);
_aggregator.start();
} catch (Exception e) {
logger.error("Aggregator failed to become leader from stand by for view cluster {}",
viewClusterName, e);
reset();
throw e;
}
logStateTransition("STANDBY", "LEADER", message.getPartitionName(), message.getTgtName());

}

@@ -86,15 +82,12 @@ public void onBecomeDroppedFromOffline(Message message, NotificationContext cont
logStateTransition("OFFLINE", "DROPPED", message.getPartitionName(), message.getTgtName());
}


@Override
public void reset() {
synchronized (stateTransitionLock) {
if (_aggregator != null) {
logger.error("Resetting view aggregator {}", _aggregator.getAggregatorInstanceName());
_aggregator.shutdown();
_aggregator = null;
}
if (_aggregator != null) {
logger.info("Resetting view aggregator {}", _aggregator.getAggregatorInstanceName());
_aggregator.shutdown();
_aggregator = null;
}
}

@@ -56,6 +56,7 @@ public class TestHelixViewAggregator extends ViewAggregatorIntegrationTestBase {
private HelixAdmin _helixAdmin;
private MockViewClusterSpectator _monitor;
private Set<String> _allResources = new HashSet<>();
// TODO: add test coverage on multiple statemodel instances for different view clusters
private DistViewAggregatorStateModel _viewAggregatorStateModel;

@BeforeClass

0 comments on commit 5909a8a

Please sign in to comment.