Remove a redundant condition check

Started by Ádám Baloghover 5 years ago6 messages
#1Ádám Balogh
adam.balogh@ericsson.com
1 attachment(s)

Hello,

A one line change to remove a duplicate check. This duplicate check was detected during testing my contribution to a static code analysis tool. There is no functional change, no new tests needed.

Regards,

Ádám Balogh
CodeChecker Team
Ericsson Hungary

Attachments:

v1-0001-Remove-redundant-condition.patchapplication/octet-stream; name=v1-0001-Remove-redundant-condition.patchDownload
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index e455384b5b..fd93bcfaeb 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7375,11 +7375,11 @@ StartupXLOG(void)
 
 					/*
 					 * Wake up any walsenders to notice that we are on a new
 					 * timeline.
 					 */
-					if (switchedTLI && AllowCascadeReplication())
+					if (AllowCascadeReplication())
 						WalSndWakeup();
 				}
 
 				/* Exit loop if we reached inclusive recovery target */
 				if (recoveryStopsAfter(xlogreader))
#2Amit Kapila
amit.kapila16@gmail.com
In reply to: Ádám Balogh (#1)
Re: Remove a redundant condition check

On Thu, Jun 25, 2020 at 11:23 PM Ádám Balogh <adam.balogh@ericsson.com> wrote:

A one line change to remove a duplicate check. This duplicate check was detected during testing my contribution to a static code analysis tool. There is no functional change, no new tests needed.

Yeah, this duplicate check is added as part of commit b2a5545bd6. See
below part of change.

- /*
- * If this record was a timeline switch, wake up any
- * walsenders to notice that we are on a new timeline.
- */
- if (switchedTLI && AllowCascadeReplication())
- WalSndWakeup();
+ /* Is this a timeline switch? */
+ if (switchedTLI)
+ {
+ /*
+ * Before we continue on the new timeline, clean up any
+ * (possibly bogus) future WAL segments on the old timeline.
+ */
+ RemoveNonParentXlogFiles(EndRecPtr, ThisTimeLineID);
+
+ /*
+ * Wake up any walsenders to notice that we are on a new
+ * timeline.
+ */
+ if (switchedTLI && AllowCascadeReplication())
+ WalSndWakeup();
+ }

It seems we forgot to remove the additional check for switchedTLI
while adding a new check. I think we can remove this duplicate check
in the HEAD code. I am not sure if it is worth to backpatch such a
change.

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

#3Michael Paquier
michael@paquier.xyz
In reply to: Amit Kapila (#2)
Re: Remove a redundant condition check

On Fri, Jun 26, 2020 at 02:39:22PM +0530, Amit Kapila wrote:

It seems we forgot to remove the additional check for switchedTLI
while adding a new check. I think we can remove this duplicate check
in the HEAD code. I am not sure if it is worth to backpatch such a
change.

Yes, there is no point to keep this check so let's clean up this
code. I also see no need to do a backpatch here, this is purely
cosmetic.
--
Michael

#4Ádám Balogh
adam.balogh@ericsson.com
In reply to: Amit Kapila (#2)
RE: Remove a redundant condition check

Hello,

-----Original Message-----
From: Amit Kapila <amit.kapila16@gmail.com>
Sent: 2020. június 26., péntek 11:09
To: Ádám Balogh <adam.balogh@ericsson.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: Re: Remove a redundant condition check

On Thu, Jun 25, 2020 at 11:23 PM Ádám Balogh <adam.balogh@ericsson.com> wrote:

A one line change to remove a duplicate check. This duplicate check was detected during testing my contribution to a static code analysis tool. There is no functional change, no new tests needed.

Yeah, this duplicate check is added as part of commit b2a5545bd6. See below part of change.

- /*
- * If this record was a timeline switch, wake up any
- * walsenders to notice that we are on a new timeline.
- */
- if (switchedTLI && AllowCascadeReplication())
- WalSndWakeup();
+ /* Is this a timeline switch? */
+ if (switchedTLI)
+ {
+ /*
+ * Before we continue on the new timeline, clean up any
+ * (possibly bogus) future WAL segments on the old timeline.
+ */
+ RemoveNonParentXlogFiles(EndRecPtr, ThisTimeLineID);
+
+ /*
+ * Wake up any walsenders to notice that we are on a new
+ * timeline.
+ */
+ if (switchedTLI && AllowCascadeReplication()) WalSndWakeup(); }

It seems we forgot to remove the additional check for switchedTLI while adding a new check. I think we can remove this duplicate > > check in the HEAD code. I am not sure if it is worth to backpatch such a change.

Thank you for confirming it. I do not think it is worth to backpatch, it is just a readability issue.
Regards,

Ádám

#5Ranier Vilela
ranier.vf@gmail.com
In reply to: Amit Kapila (#2)
Re: Remove a redundant condition check

Em sex., 26 de jun. de 2020 às 06:09, Amit Kapila <amit.kapila16@gmail.com>
escreveu:

On Thu, Jun 25, 2020 at 11:23 PM Ádám Balogh <adam.balogh@ericsson.com>
wrote:

A one line change to remove a duplicate check. This duplicate check was

detected during testing my contribution to a static code analysis tool.
There is no functional change, no new tests needed.

Yeah, this duplicate check is added as part of commit b2a5545bd6. See
below part of change.

- /*
- * If this record was a timeline switch, wake up any
- * walsenders to notice that we are on a new timeline.
- */
- if (switchedTLI && AllowCascadeReplication())
- WalSndWakeup();
+ /* Is this a timeline switch? */
+ if (switchedTLI)
+ {
+ /*
+ * Before we continue on the new timeline, clean up any
+ * (possibly bogus) future WAL segments on the old timeline.
+ */
+ RemoveNonParentXlogFiles(EndRecPtr, ThisTimeLineID);
+
+ /*
+ * Wake up any walsenders to notice that we are on a new
+ * timeline.
+ */
+ if (switchedTLI && AllowCascadeReplication())
+ WalSndWakeup();
+ }

It seems we forgot to remove the additional check for switchedTLI
while adding a new check. I think we can remove this duplicate check
in the HEAD code. I am not sure if it is worth to backpatch such a
change.

+1
Great to know, that this is finally going to be fixed. (1)

regards,
Ranier Vilela
1.
/messages/by-id/CAEudQAocMqfqt0t64HNo39Z73jMey60WmeryB+WFDg3BZpCf=g@mail.gmail.com

#6Amit Kapila
amit.kapila16@gmail.com
In reply to: Michael Paquier (#3)
Re: Remove a redundant condition check

On Fri, Jun 26, 2020 at 3:32 PM Michael Paquier <michael@paquier.xyz> wrote:

On Fri, Jun 26, 2020 at 02:39:22PM +0530, Amit Kapila wrote:

It seems we forgot to remove the additional check for switchedTLI
while adding a new check. I think we can remove this duplicate check
in the HEAD code. I am not sure if it is worth to backpatch such a
change.

Yes, there is no point to keep this check so let's clean up this
code. I also see no need to do a backpatch here, this is purely
cosmetic.

Thanks for the confirmation, pushed!

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com