Skip to content

Commit

Permalink
poolmanager: avoid duplicating magic numbers
Browse files Browse the repository at this point in the history
Motivation:

Several places set the error to zero to reset the result back to a
success.  Avoid this duplication.

Modification:

Introduce a new method that clears the error.

Remove some redundant calls to clear the error: these return a code that
triggers a subsequent error-clearing step.

Reorder some error-clearing calls so it appears immediately before the
nextStep call.

Result:

No user or admin obserable changes.

Code is slightly easier to read and understand.

Target: master
Requires-notes: no
Requires-book: no
Patch: https://rb.dcache.org/r/12782/
Acked-by: Lea Morschel
Acked-by: Albert Rossi
  • Loading branch information
paulmillar committed Jan 25, 2021
1 parent 80d5540 commit 924f1c1
Showing 1 changed file with 14 additions and 15 deletions.
Expand Up @@ -1086,6 +1086,10 @@ private void clearSteering() {
_waitingFor = null;
}
}
private void clearError() {
_currentRc = 0;
_currentRm = "";
}
private void setError( int errorCode , String errorMessage ){
_currentRc = errorCode ;
_currentRm = errorMessage ;
Expand Down Expand Up @@ -1504,15 +1508,14 @@ private void stateEngine( Object inputObject ) {

//
//
if( _enforceP2P ){
setError(0,"");
if (_enforceP2P) {
clearError();
nextStep(RequestState.ST_POOL_2_POOL);
return ;
}

if( ( rc = askIfAvailable() ) == RequestStatusCode.FOUND ){

setError(0,"");
if ((rc = askIfAvailable()) == RequestStatusCode.FOUND) {
clearError();
nextStep(RequestState.ST_DONE) ;
_log.info("AskIfAvailable found the object");
if (_sendHitInfo) {
Expand Down Expand Up @@ -1577,9 +1580,9 @@ private void stateEngine( Object inputObject ) {
{
if( ( rc = askForPoolToPool( _overwriteCost ) ) == RequestStatusCode.FOUND ){

clearError();
nextStep(RequestState.ST_WAITING_FOR_POOL_2_POOL);
_status = "Pool2Pool "+ LocalDateTime.now().format(DATE_TIME_FORMAT);
setError(0, "");

if (_sendHitInfo) {
sendHitMsg(_p2pSourcePool.info(), true); //VP
Expand All @@ -1600,8 +1603,8 @@ private void stateEngine( Object inputObject ) {
_poolCandidate = _bestPool;
_log.info("ST_POOL_2_POOL : Choosing high cost pool {}", _poolCandidate.info());

setError(0,"");
nextStep(RequestState.ST_DONE);
clearError();
nextStep(RequestState.ST_DONE);
}

}else if( rc == RequestStatusCode.S_COST_EXCEEDED ){
Expand All @@ -1621,7 +1624,7 @@ private void stateEngine( Object inputObject ) {
if( _bestPool != null ){
_poolCandidate = _bestPool;
_log.info("ST_POOL_2_POOL : Choosing high cost pool {}", _poolCandidate.info());
setError(0,"");
clearError();
}else{
//
// this can't possibly happen
Expand All @@ -1643,7 +1646,7 @@ private void stateEngine( Object inputObject ) {
}else{
_poolCandidate = _bestPool;
_log.info(" found high cost object");
setError(0,"");
clearError();
}
nextStep(RequestState.ST_DONE);

Expand All @@ -1669,10 +1672,9 @@ private void stateEngine( Object inputObject ) {
}

if( ( rc = askForStaging() ) == RequestStatusCode.FOUND ){

clearError();
nextStep(RequestState.ST_WAITING_FOR_STAGING);
_status = "Staging "+ LocalDateTime.now().format(DATE_TIME_FORMAT);
setError(0, "");

} else if (rc == RequestStatusCode.OUT_OF_RESOURCES) {
_restoreExceeded++;
Expand Down Expand Up @@ -1928,7 +1930,6 @@ private RequestStatusCode askIfAvailable()
}

_poolCandidate = _bestPool;
setError(0,"");
return RequestStatusCode.FOUND;
}
//
Expand Down Expand Up @@ -2012,8 +2013,6 @@ private RequestStatusCode askForStaging()
return RequestStatusCode.OUT_OF_RESOURCES;
}

setError(0,"");

return RequestStatusCode.FOUND;
} catch (CostException e) {
if (e.getPool() != null) {
Expand Down

0 comments on commit 924f1c1

Please sign in to comment.