Refactor: based, libcib: More refactors around based_process_request() and helpers#4122
Conversation
If file_perform_op_delegate()'s output_data argument is NULL, then we would just free the copy (output) as soon as we return from process_request(). Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
cib_file.c was already checking for this and would not free output if it was part of the same doc as the current CIB. The CIB manager was preserving output only if it was equal to the current CIB. So we just have to update the CIB manager to compare the docs, and update cib__perform_op_ro() to skip the copy if the docs are the same. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
And drop an unhelpful trace message in cib__perform_op_rw(). Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The other two were already in based_process_request(). Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
And rename to based_perform_op_rw(). Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
"Create" is the only read-write operation that may set *output. There is no path by which a create operation can return pcmk_rc_schema_validation. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
If a request within a transaction succeeds, we don't want to discard the result CIB. We need it for the next request in the transaction, or for the end result if this is the last request to process. So we want to activate it. However, we do NOT want to write it to disk. If the system or CIB manager crashes while committing a transaction, and we restore an intermediate result, the transaction was not atomic. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
We get the same information from log_op_result() and do_local_notify(). Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
We make this change despite the previous comment saying we wanted log messages and the target check. Some of the messages are misleading or confusing in the context of a within-transaction request, and skipping that call will facilitate some other changes. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Pull the check inline. If it's true, then we can call forward_request() and return immediately. We can also drop the trace message, because we have one in forward_request(). Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
It doesn't seem very helpful. We know that if we receive a request from a local client and it's either a modifying request or addressed to another node (or to all nodes), we'll forward it. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
I really don't think it's relevant now, though I could be wrong. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
40551d8 to
62ea742
Compare
|
Rebased on main to resolve conflict. |
|
|
||
| } else if (!parse_peer_options(operation, request, &local_notify, | ||
| &needs_reply, &process)) { | ||
| return pcmk_rc_ok; |
There was a problem hiding this comment.
This patch makes me a little bit nervous, though without really digging into the based code I don't have any specific reason for it. The call to process_ping_reply hiding in parse_peer_options certainly doesn't help matters.
There was a problem hiding this comment.
This patch makes me a little bit nervous, though without really digging into the based code I don't have any specific reason for it.
All we really need to worry about is checking what the values of these booleans are before calling parse_peer_options(), and making sure this preserves behavior. They all have default values of either true or false. There aren't that many changes to look at. I'll break it up to try to make it clearer though.
There was a problem hiding this comment.
The call to
process_ping_replyhiding inparse_peer_actionscertainly doesn't help matters.
Agreed. This will go away in 3fa5f4e.
|
|
||
| if (pcmk__str_eq(host, OUR_NODENAME, pcmk__str_casei)) { | ||
| pcmk__trace("Processing %s request sent to us from %s", op, originator); | ||
| *needs_reply = true; |
There was a problem hiding this comment.
It seems like one of these two needs_reply lines still needs to be here.
There was a problem hiding this comment.
Not sure. I think I address that a few lines later with the early return true followed by *needs_reply = false. I'm not sure why I have return true instead of logging the trace message though.
The upcoming push has each of the three variables in its own commit. So hopefully that will make these changes easier to review.
Nothing uses it internally. sync_from is still available. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
These are mutually exclusive with the other cases that appeared earlier in the if/else chain. * If op is CRM_OP_PING or PCMK__CIB_REQUEST_SHUTDOWN, then it isn't PCMK__CIB_REQUEST_REPLACE, PCMK__CIB_REQUEST_SYNC, or PCMK__CIB_REQUEST_UPGRADE. * If op is PCMK__CIB_REQUEST_SHUTDOWN, then the cib__op_attr_modifies flag isn't set. Also, return true explicitly from the shutdown case, and don't set *process. It's already set to true when this function is called. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
This was added by commit 15c4d2a to deal with legacy mode. We haven't supported legacy mode (which was for clusters with pre-1.1.12 systems) since 3.0.0. Currently, the only modifying ops that may set PCMK__XA_CIB_ISREPLYTO are replace (as a sync reply) and upgrade. Those two cases are explicitly addressed here. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
This is an incremental change; more is coming. Yes, this introduces duplication. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Any PCMK__CIB_REQUEST_UPGRADE with PCMK__XA_CIB_UPGRADE_RC set also has PCMK__XA_CIB_ISREPLYTO set. The cluster message is addressed to the isreplyto host (see based_process_upgrade()), which must be non-NULL because origin is non-NULL. So we cannot receive a cluster message with PCMK__XA_CIB_UPGRADE_RC and a NULL host. If we receive a message that is addressed to some OTHER host, we drop it. cib_cs_dispatch() calls pcmk__cpg_message_data(), which ignores messages that aren't for the local node. Therefore, if we're processing a PCMK__CIB_REQUEST_UPGRADE request with PCMK__XA_CIB_UPGRADE_RC set, then is_reply must be true. Note that the equivalent of PCMK__XA_CIB_UPGRADE_RC was introduced by commit 1f05f5e. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
...in parse_peer_options(). Another incremental change for easy review.
Note that the direct negation of the conditions that came before the
previous "return false" would be
if (((max != NULL) || !based_is_primary)
&& (max == NULL)) {
...
}
It cannot be the case that (max == NULL) and (max != NULL), so we can
replace ((max != NULL) || !based_is_primary) with !based_is_primary.
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
But not the code below it. I've come to appreciate a nice "goto done" or similar, but in this case removing the label seems to make things less convoluted, at least for now. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
It doesn't really do anything now. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The process variable is set to true as a default value in based_process_request(). In a couple of places, we explicitly set it to true again. This was likely to clarify the end state, since the parsing is rather convoluted. However, removing these redundant sets is an incremental step toward simplifying the option parsing. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The local_notify variable is set to false as a default value in based_process_request(). In a couple of places, we explicitly set it to false again. This was likely to clarify the end state, since the parsing is rather convoluted. However, removing these redundant sets is an incremental step toward simplifying the option parsing. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The needs_reply variable is set to true as a default value in based_process_request(). In a couple of places, we explicitly set it to true again. This was likely to clarify the end state, since the parsing is rather convoluted. However, removing these redundant sets is an incremental step toward simplifying the option parsing. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
62ea742 to
11565df
Compare
Next batch from #4011