Skip to content

Commit

Permalink
Revise migration state machine to use notifyCompletedWithMessage()
Browse files Browse the repository at this point in the history
* Remove entry action for `Done` state and replace with appropriate
  transition action.

* Add new FSM action `notifyCompletedWithInsufficientReplicas()`.

* Add new guarded transitions to `Done` which invoke
  `notifyCompletedWithInsufficientReplicas()` when appropriate.

* Update state machine diagram.
  • Loading branch information
greenc-FNAL committed Dec 16, 2024
1 parent 0fa28cc commit c85e852
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 10 deletions.
14 changes: 14 additions & 0 deletions modules/dcache/src/main/java/org/dcache/pool/migration/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ synchronized boolean needsMoreReplicas() {
return _replicas.size() < _parameters.replicas;
}

synchronized boolean moreReplicasPossible() {
return _parameters.waitForTargets || (_replicas.size() < _parameters.poolList.getPools().size());
}

/**
* FSM Action
*/
Expand Down Expand Up @@ -347,6 +351,16 @@ void notifyCompleted() {
new FireAndForgetTask(() -> _callbackHandler.taskCompleted(Task.this)));
}

/**
* FSM Action
*/
void notifyCompletedWithInsufficientReplicas() {
_parameters.executor.execute(
new FireAndForgetTask(() -> _callbackHandler.taskCompletedWithNote(Task.this,
String.format("File replicas truncated at %s due to pool availability (%s requested)",
_replicas.size(), _parameters.replicas))));
}

/**
* FSM Action
*/
Expand Down
33 changes: 32 additions & 1 deletion modules/dcache/src/main/smc/org/dcache/pool/migration/Task.sm
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ Entry
messageArrived(message: PoolMigrationCopyFinishedMessage)
Done
{
notifyCompleted();
}

}
Expand Down Expand Up @@ -266,6 +267,7 @@ Entry
messageArrived(message: PoolMigrationCopyFinishedMessage)
Done
{
notifyCompleted();
}
}

Expand Down Expand Up @@ -359,6 +361,12 @@ Exit
UpdatingExistingFile
{
}
messageArrived(message: PoolMigrationCopyFinishedMessage)
[ ctxt.needsMoreReplicas() && ! (ctxt.moreReplicasPossible() || ctxt.isMetaOnly()) ]
Done
{
notifyCompletedWithInsufficientReplicas();
}
messageArrived(message: PoolMigrationCopyFinishedMessage)
[ ctxt.needsMoreReplicas() && !ctxt.isMetaOnly() ]
InitiatingCopy
Expand All @@ -378,6 +386,7 @@ Exit
messageArrived(message: PoolMigrationCopyFinishedMessage)
Done
{
notifyCompleted();
}
cancel
Cancelling
Expand Down Expand Up @@ -435,6 +444,12 @@ Entry
UpdatingExistingFile
{
}
messageArrived(message: PoolMigrationCopyFinishedMessage)
[ ctxt.needsMoreReplicas() && ! (ctxt.moreReplicasPossible() || ctxt.isMetaOnly()) ]
Done
{
notifyCompletedWithInsufficientReplicas();
}
messageArrived(message: PoolMigrationCopyFinishedMessage)
[ ctxt.needsMoreReplicas() && !ctxt.isMetaOnly() ]
InitiatingCopy
Expand All @@ -454,6 +469,7 @@ Entry
messageArrived(message: PoolMigrationCopyFinishedMessage)
Done
{
notifyCompleted();
}
cancel
Cancelling
Expand Down Expand Up @@ -527,6 +543,12 @@ Exit
UpdatingExistingFile
{
}
messageArrived(message: PoolMigrationCopyFinishedMessage)
[ ctxt.needsMoreReplicas() && ! (ctxt.moreReplicasPossible() || ctxt.isMetaOnly()) ]
Done
{
notifyCompletedWithInsufficientReplicas();
}
messageArrived(message: PoolMigrationCopyFinishedMessage)
[ ctxt.needsMoreReplicas() && !ctxt.isMetaOnly() ]
InitiatingCopy
Expand All @@ -546,6 +568,7 @@ Exit
messageArrived(message: PoolMigrationCopyFinishedMessage)
Done
{
notifyCompleted();
}
cancel
Cancelling
Expand Down Expand Up @@ -595,6 +618,12 @@ Exit
UpdatingExistingFile
{
}
messageArrived(message: PoolMigrationCopyFinishedMessage)
[ ctxt.needsMoreReplicas() && ! (ctxt.moreReplicasPossible() || ctxt.isMetaOnly()) ]
Done
{
notifyCompletedWithInsufficientReplicas();
}
messageArrived(message: PoolMigrationCopyFinishedMessage)
[ ctxt.needsMoreReplicas() && !ctxt.isMetaOnly() ]
InitiatingCopy
Expand All @@ -614,6 +643,7 @@ Exit
messageArrived(message: PoolMigrationCopyFinishedMessage)
Done
{
notifyCompleted();
}
}

Expand All @@ -626,6 +656,7 @@ Entry
move_success
Done
{
notifyCompleted();
}
move_failure(rc: Integer, cause: Object)
Failed
Expand Down Expand Up @@ -689,6 +720,7 @@ Exit
[ message.getReturnCode() == 0 ]
Done
{
notifyCompleted();
}
cancel_success
nil
Expand Down Expand Up @@ -731,7 +763,6 @@ Failed
Done
Entry
{
notifyCompleted();
}
{
}
Expand Down
30 changes: 21 additions & 9 deletions modules/dcache/src/main/smc/org/dcache/pool/migration/Task_sm.dot
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ digraph Task {
[label="{Failed|Default()/\l}"];

"TASK::Done"
[label="{Done|Entry/\l&nbsp;&nbsp;&nbsp;notifyCompleted();\l|Default()/\l}"];
[label="{Done|Entry/\l|Default()/\l}"];

"%start"
[label="" shape=circle style=filled fillcolor=black width=0.25];
Expand Down Expand Up @@ -143,7 +143,7 @@ digraph Task {
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.getMustMovePins() \]/\l"];

"TASK::UpdatingExistingFile" -> "TASK::Done"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)/\l"];
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)/\lnotifyCompleted();\l"];

"TASK::InitiatingCopy" -> "TASK::Copying"
[label="copy_success()/\l"];
Expand Down Expand Up @@ -187,7 +187,7 @@ digraph Task {
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.getMustMovePins() \]/\l"];

"TASK::InitiatingCopy" -> "TASK::Done"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)/\l"];
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)/\lnotifyCompleted();\l"];

"TASK::WaitingForCopyReplicaReply" -> "TASK::UpdatingExistingFile"
[label="copy_success()\l\[ ctxt.hasMoreLocations() \]/\l"];
Expand Down Expand Up @@ -232,6 +232,9 @@ digraph Task {
"TASK::Copying" -> "TASK::UpdatingExistingFile"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.needsMoreReplicas() && ctxt.hasMoreLocations() \]/\l"];

"TASK::Copying" -> "TASK::Done"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.needsMoreReplicas() && ! (ctxt.moreReplicasPossible() || ctxt.isMetaOnly()) \]/\lnotifyCompletedWithInsufficientReplicas();\l"];

"TASK::Copying" -> "TASK::InitiatingCopy"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.needsMoreReplicas() && !ctxt.isMetaOnly() \]/\l"];

Expand All @@ -242,7 +245,7 @@ digraph Task {
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.getMustMovePins() \]/\l"];

"TASK::Copying" -> "TASK::Done"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)/\l"];
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)/\lnotifyCompleted();\l"];

"TASK::Copying" -> "TASK::Cancelling"
[label="cancel()/\l"];
Expand Down Expand Up @@ -272,6 +275,9 @@ digraph Task {
"TASK::Pinging" -> "TASK::UpdatingExistingFile"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.needsMoreReplicas() && ctxt.hasMoreLocations() \]/\l"];

"TASK::Pinging" -> "TASK::Done"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.needsMoreReplicas() && ! (ctxt.moreReplicasPossible() || ctxt.isMetaOnly()) \]/\lnotifyCompletedWithInsufficientReplicas();\l"];

"TASK::Pinging" -> "TASK::InitiatingCopy"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.needsMoreReplicas() && !ctxt.isMetaOnly() \]/\l"];

Expand All @@ -282,7 +288,7 @@ digraph Task {
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.getMustMovePins() \]/\l"];

"TASK::Pinging" -> "TASK::Done"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)/\l"];
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)/\lnotifyCompleted();\l"];

"TASK::Pinging" -> "TASK::Cancelling"
[label="cancel()/\l"];
Expand Down Expand Up @@ -314,6 +320,9 @@ digraph Task {
"TASK::NoResponse" -> "TASK::UpdatingExistingFile"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.needsMoreReplicas() && ctxt.hasMoreLocations() \]/\l"];

"TASK::NoResponse" -> "TASK::Done"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.needsMoreReplicas() && ! (ctxt.moreReplicasPossible() || ctxt.isMetaOnly()) \]/\lnotifyCompletedWithInsufficientReplicas();\l"];

"TASK::NoResponse" -> "TASK::InitiatingCopy"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.needsMoreReplicas() && !ctxt.isMetaOnly() \]/\l"];

Expand All @@ -324,7 +333,7 @@ digraph Task {
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.getMustMovePins() \]/\l"];

"TASK::NoResponse" -> "TASK::Done"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)/\l"];
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)/\lnotifyCompleted();\l"];

"TASK::NoResponse" -> "TASK::Cancelling"
[label="cancel()/\l"];
Expand All @@ -346,6 +355,9 @@ digraph Task {
"TASK::WaitingForCopyFinishedMessage" -> "TASK::UpdatingExistingFile"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.needsMoreReplicas() && ctxt.hasMoreLocations() \]/\l"];

"TASK::WaitingForCopyFinishedMessage" -> "TASK::Done"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.needsMoreReplicas() && ! (ctxt.moreReplicasPossible() || ctxt.isMetaOnly()) \]/\lnotifyCompletedWithInsufficientReplicas();\l"];

"TASK::WaitingForCopyFinishedMessage" -> "TASK::InitiatingCopy"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.needsMoreReplicas() && !ctxt.isMetaOnly() \]/\l"];

Expand All @@ -356,10 +368,10 @@ digraph Task {
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ ctxt.getMustMovePins() \]/\l"];

"TASK::WaitingForCopyFinishedMessage" -> "TASK::Done"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)/\l"];
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)/\lnotifyCompleted();\l"];

"TASK::MovingPin" -> "TASK::Done"
[label="move_success()/\l"];
[label="move_success()/\lnotifyCompleted();\l"];

"TASK::MovingPin" -> "TASK::Failed"
[label="move_failure(rc: Integer, cause: Object)/\lfail(rc, \"Pin manager failed (\" + cause + \")\");\l"];
Expand All @@ -386,7 +398,7 @@ digraph Task {
ctxt.getCancelReason()));\l"];

"TASK::Cancelling" -> "TASK::Done"
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ message.getReturnCode() == 0 \]/\l"];
[label="messageArrived(message: PoolMigrationCopyFinishedMessage)\l\[ message.getReturnCode() == 0 \]/\lnotifyCompleted();\l"];

"TASK::Cancelling" -> "TASK::Failed"
[label="cancel_noroute()/\lfail(SERVICE_UNAVAILABLE, String.format(\"Cancelling task (%s) failed (no route)\",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c85e852

Please sign in to comment.