Skip to content

Commit

Permalink
[irods#7918] replica_truncate: Fix JSON output for some cases
Browse files Browse the repository at this point in the history
The replica_truncate API has a JSON-based message in its output string
which is meant to communicate error information as well as information
about the replica which was truncated or targeted for truncate. The API
up to this point has only been communicating information back to clients
in the failure cases. It is most useful to communicate the replica
information to the client in the success cases. This change fixes that.

This change also adjusts the JSON output from the case where the target
replica is not in the hierarchy requested by the client via the RESC_NAME_KW.
Before, this case would return the replica information for the replica which
won the vote, but the JSON now returns no replica information because the
replica which the client wanted to target either does not exist or is not
accessible for truncating. Returning the replica information in this case
is incorrect because showing the replica which did win the vote could give
the impression that it was truncated when in fact it was not.
  • Loading branch information
alanking committed Jul 25, 2024
1 parent 046238b commit 4772027
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server/api/src/rs_replica_truncate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,11 @@ auto rs_replica_truncate(RsComm* _comm, DataObjInp* _inp, char** _out) -> int
resource_name,
_inp->objPath);
log_api::error(msg);
*_out = strdup(make_json_output(msg, replica).dump().c_str());
// Even though we have replica information, do not include it in the output structure. This error case is
// specifically about the selected replica not being in the hierarchy descending from the client-requested
// resource, so we do not care to include that information in the output. It could give the impression that
// the replica from the returned information was truncated when in fact it was not.
*_out = strdup(make_json_output(msg).dump().c_str());
return SYS_REPLICA_INACCESSIBLE;
}

Expand Down Expand Up @@ -313,6 +317,9 @@ auto rs_replica_truncate(RsComm* _comm, DataObjInp* _inp, char** _out) -> int
*_out = strdup(make_json_output(msg, replica).dump().c_str());
return ec;
}

// The output structure is meant to communicate back to the client which replica was truncated.
*_out = strdup(make_json_output("", replica).dump().c_str());
}
catch (const irods::exception& e) {
log_api::error("{}: Failed to truncate [{}]: {}", __func__, _inp->objPath, e.client_display_what());
Expand Down

0 comments on commit 4772027

Please sign in to comment.