Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for keepalive issue #445 #446

Merged
merged 3 commits into from
Nov 3, 2022
Merged

Fix for keepalive issue #445 #446

merged 3 commits into from
Nov 3, 2022

Conversation

sm-shaw
Copy link
Contributor

@sm-shaw sm-shaw commented Oct 7, 2022

Fixes issue #445 where keepalive time is not detected if either are zero and adds user configurable keepalive time.
Also fixes issue with vucreate automatically running loadscript if script is not already loaded.

@sm-shaw sm-shaw requested a review from a team as a code owner October 7, 2022 11:20
@sm-shaw sm-shaw linked an issue Oct 7, 2022 that may be closed by this pull request
upvar #0 genericdict genericdict
if {[dict exists $genericdict commandline keepalive_margin]} {
set ka_margin [ dict get $genericdict commandline keepalive_margin]
if {![string is entier $ka_margin]} { set ka_margin 10 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if and else branches do the same thing - do we need the condition at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so - the genericdict has a new entry as below in the XML config files and this also gets stored in the SQLite files as well.

<commandline>
       <keepalive_margin>10</keepalive_margin>
</commandline>

all of the XML files get stored as global dicts on startup, upvar allows us to access this dict on a higher level.
The user could potentially corrupt this entry by editing the file so either it will not be there, or it could not be set to a valid integer that we can do calculations with. So the first if/else checks if there is an entry in the genericdict before we start to use it, otherwise it would give an uncaught error so instead in this case it gets set to a default of 10. (This would also happen if the XML is updated but not the SQLite files) If the first is passed and an entry is found the 2nd if/else then checks if this is a valid integer (https://core.tcl-lang.org/tips/doc/trunk/tip/395.md) if it is not (![string is entier $ka_margin]) e.g. someone changed the entry to "true" misunderstanding the value, then it also gets set to a default of 10.

We can potentially compress this to use an && for the 2 statements as Tcl will short circuit if the first argument (exists) is not true so will not evaluate the 2nd (is entier - instead of is not entier) - however doing this you need to know Tcl does this - so as it stands is safer as if you reversed the 2 && arguments and the dict entry didn't exist but was evaluated 2nd it would give an uncaught error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand now. I had misread the code.

I thought the else on line 1062 was for the if on line 1061, but it's actually for the if on line 1059.

Can we fix the indentation on lines 1062-1064 so that it is aligned properly with line 1059?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the indentation. There is a package included with HammerDB called reformat_tcl. You can do "package require reformat_tcl" and then reformat_src indent filename, and it will update the file with the correct indentation. This should server as a prompt for me to use it to prevent less confusion going forward.

Copy link
Contributor Author

@sm-shaw sm-shaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finish review

upvar #0 genericdict genericdict
if {[dict exists $genericdict commandline keepalive_margin]} {
set ka_margin [ dict get $genericdict commandline keepalive_margin]
if {![string is entier $ka_margin]} { set ka_margin 10 }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so - the genericdict has a new entry as below in the XML config files and this also gets stored in the SQLite files as well.

<commandline>
       <keepalive_margin>10</keepalive_margin>
</commandline>

all of the XML files get stored as global dicts on startup, upvar allows us to access this dict on a higher level.
The user could potentially corrupt this entry by editing the file so either it will not be there, or it could not be set to a valid integer that we can do calculations with. So the first if/else checks if there is an entry in the genericdict before we start to use it, otherwise it would give an uncaught error so instead in this case it gets set to a default of 10. (This would also happen if the XML is updated but not the SQLite files) If the first is passed and an entry is found the 2nd if/else then checks if this is a valid integer (https://core.tcl-lang.org/tips/doc/trunk/tip/395.md) if it is not (![string is entier $ka_margin]) e.g. someone changed the entry to "true" misunderstanding the value, then it also gets set to a default of 10.

We can potentially compress this to use an && for the 2 statements as Tcl will short circuit if the first argument (exists) is not true so will not evaluate the 2nd (is entier - instead of is not entier) - however doing this you need to know Tcl does this - so as it stands is safer as if you reversed the 2 && arguments and the dict entry didn't exist but was evaluated 2nd it would give an uncaught error.

Copy link
Contributor Author

@sm-shaw sm-shaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requested changes to indentation added.

@abondvt89
Copy link
Contributor

Merging after reviews and approval of the three members of the code maintenance team.

@abondvt89 abondvt89 merged commit ffe1409 into TPC-Council:master Nov 3, 2022
@sm-shaw sm-shaw deleted the 445 branch November 23, 2022 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v4.6 keepalive not active when rampup or duration is 0
3 participants