From 18fa01eccde0a954ee5a70463bf81f6cb447fadc Mon Sep 17 00:00:00 2001 From: Alan King Date: Tue, 23 Jul 2024 11:35:34 -0400 Subject: [PATCH] [#7918] replica_truncate: Fix JSON output for some cases 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. --- server/api/src/rs_replica_truncate.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/api/src/rs_replica_truncate.cpp b/server/api/src/rs_replica_truncate.cpp index e70e24c3db..86c590e83c 100644 --- a/server/api/src/rs_replica_truncate.cpp +++ b/server/api/src/rs_replica_truncate.cpp @@ -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; } @@ -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());