Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combine PropertyStoreTask and MysqlTask to use same factory name #2961

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ public void participate(List<AmbryStatsReport> ambryStatsReports, AccountStatsSt
StateMachineEngine stateMachineEngine = manager.getStateMachineEngine();
stateMachineEngine.registerStateModelFactory(clusterMapConfig.clustermapStateModelDefinition,
new AmbryStateModelFactory(clusterMapConfig, this, clusterManager));
registerStatsReportAggregationTasks(stateMachineEngine, ambryStatsReports, accountStatsStore, callback);
registerPropertyStoreCleanUpTask(stateMachineEngine);
registerTasks(stateMachineEngine, ambryStatsReports, accountStatsStore, callback);
try {
// register server as a participant
manager.connect();
Expand Down Expand Up @@ -799,41 +798,36 @@ private void awaitDisablingPartition() throws InterruptedException {
}

/**
* Register aggregation tasks for appropriate {@link AmbryStatsReport}s.
* This method will register Helix Tasks
* Register aggregation tasks for appropriate {@link AmbryStatsReport}s and {@link PropertyStoreCleanUpTask}.
* @param engine the {@link StateMachineEngine} to register the task state model.
* @param statsReports the {@link List} of {@link AmbryStatsReport}s that may require the registration of
* corresponding {@link MySqlReportAggregatorTask}s.
* @param accountStatsStore the {@link AccountStatsStore} to retrieve and store container stats.
* @param callback a callback which will be invoked when the aggregation report has been generated successfully.
*/
private void registerStatsReportAggregationTasks(StateMachineEngine engine, List<AmbryStatsReport> statsReports,
private void registerTasks(StateMachineEngine engine, List<AmbryStatsReport> statsReports,
AccountStatsStore accountStatsStore, Callback<AggregatedAccountStorageStats> callback) {
//Register MySqlReportAggregatorTask
Map<String, TaskFactory> taskFactoryMap = new HashMap<>();
for (final AmbryStatsReport statsReport : statsReports) {
taskFactoryMap.put(
String.format("%s_%s", MySqlReportAggregatorTask.TASK_COMMAND_PREFIX, statsReport.getReportName()),
context -> new MySqlReportAggregatorTask(context.getManager(), statsReport.getAggregateIntervalInMinutes(),
statsReport.getStatsReportType(), accountStatsStore, callback, clusterMapConfig, metricRegistry));
}
if (!taskFactoryMap.isEmpty()) {
engine.registerStateModelFactory(TaskConstants.STATE_MODEL_NAME,
new TaskStateModelFactory(manager, taskFactoryMap));
}
}

/**
* Register Property Store Clean Up Task for cleaning up expired {@link DataNodeConfig} in Property Store.
* @param engine the {@link StateMachineEngine} to register the task state model.
*/
private void registerPropertyStoreCleanUpTask(StateMachineEngine engine){
//Register PropertyStoreTask
if(clusterMapConfig.clustermapEnablePropertyStoreCleanUpTask) {
logger.info("Registering PropertyStoreCleanUpTask");
Map<String, TaskFactory> taskFactoryMap = new HashMap<>();
taskFactoryMap.put(PropertyStoreCleanUpTask.COMMAND,
context -> new PropertyStoreCleanUpTask(context.getManager(), dataNodeConfigSource, clusterMapConfig,
metricRegistry));
}

if (!taskFactoryMap.isEmpty()) {
engine.registerStateModelFactory(TaskConstants.STATE_MODEL_NAME,
new TaskStateModelFactory(manager, taskFactoryMap), PropertyStoreCleanUpTask.COMMAND);
new TaskStateModelFactory(manager, taskFactoryMap));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ public void testParticipateMethodWithHelixPropertyStoreTaskEnabled() throws Exce
helixParticipant.participate( Collections.emptyList(), null, null);
assertNotNull("PropertyStoreCleanUpTask should be registered",
helixParticipant.getHelixManager().getStateMachineEngine()
.getStateModelFactory(TaskConstants.STATE_MODEL_NAME, PropertyStoreCleanUpTask.COMMAND));
.getStateModelFactory(TaskConstants.STATE_MODEL_NAME));
helixParticipant.close();

}
Expand All @@ -910,7 +910,7 @@ public void testParticipateMethodWithHelixPropertyStoreTaskDisabled() throws Exc
helixParticipant.participate(Collections.emptyList(), null, null);
assertNull("PropertyStoreCleanUpTask should not be registered",
helixParticipant.getHelixManager().getStateMachineEngine()
.getStateModelFactory(TaskConstants.STATE_MODEL_NAME, PropertyStoreCleanUpTask.COMMAND));
.getStateModelFactory(TaskConstants.STATE_MODEL_NAME));
helixParticipant.close();
}

Expand Down
Loading