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

Feature/add ti resources #21

Merged
merged 2 commits into from
Aug 19, 2022
Merged

Conversation

boltandrke
Copy link

@boltandrke boltandrke commented Aug 9, 2022

This commit will add dynamic TiKV and PD resource handling with TiDB cluster and closes issue #15
All supported TiKV and PD configuration parameters are described here

@boltandrke boltandrke force-pushed the feature/add-ti-resources branch from 3a19635 to ed35e60 Compare August 10, 2022 06:58
@borissavelev
Copy link

@petoju sorry for pinging, could you please take a look?)

Copy link
Owner

@petoju petoju left a comment

Choose a reason for hiding this comment

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

@borissavelev sorry, I was on vacation for this week and I plan being on one in the next week.

Except for some details, it looks reasonably well. I can still merge it if I get reasonable replies or changes.

GNUmakefile Outdated
@@ -52,12 +54,21 @@ testpercona:
testtidb%:
$(MAKE) MYSQL_VERSION=$* MYSQL_PORT=34$(shell echo "$*" | tr -d '.') testtidb

testtidb:
-docker run --rm --name test-tidb$(MYSQL_VERSION) -d -p $(MYSQL_PORT):4000 pingcap/tidb:v$(MYSQL_VERSION)
bin/tiup:
Copy link
Owner

Choose a reason for hiding this comment

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

Could we do the same in Docker?

Your approach forces you to start considering arch, runs with nohup, depends on some mirror without chance to cache it, there may be potentially be issues with binary compatibility on newer GLIBC and so on.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, its possible with version 4.0 as described here. But its not straight forward setup as tiup does.
Starting from version 5.0 docker is not anymore supported method pulling up the cluster.
This tool is needed only for acceptance testing. I'll glue it to am64 arch only. (similar like terraform binary fetch).

Copy link
Owner

Choose a reason for hiding this comment

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

Pingcap still publishes the docker-compose config: https://github.com/pingcap/tidb-docker-compose - but I admit it may be more complicated.

Still, if we don't want to use that - why should it run under nohup? Should it be left running in the background?

Copy link
Author

@boltandrke boltandrke Aug 17, 2022

Choose a reason for hiding this comment

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

Replaced tiup with minimal docker setup. PTAL

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks, this looks good. There is a minor issue there and I have / already had few more questions (replying you considered those is good enough for me). After that is done, I can merge it.

if isNumeric(varValue) {
configQuery = fmt.Sprintf("%s %s", configQuery, varValue)
} else {
configQuery = fmt.Sprintf("%s'%s'", configQuery, varValue)
Copy link
Owner

Choose a reason for hiding this comment

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

What if varValue contains apostrophes? Even spitting out a warning is better than nothing.

Copy link
Author

Choose a reason for hiding this comment

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

Here is an example If subsystem doesn't accept apostrophes

mysql> set config pd log.level="warn`";
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> show warnings;
+---------+------+---------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------------------------------------------+
| Warning | 1105 | bad request to http://127.0.0.1:2379/pd/api/v1/config: "log level warn is illegal"
|
+---------+------+---------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
`

It will be later rejected by warning check.

I'll add extra logging about this

Copy link
Owner

Choose a reason for hiding this comment

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

Ok, my question was maybe laid incorrectly.

Can it happen, that some value will contain apostrophe = ' character? In that case, your SQL will be invalid. BTW your new check for backticks ` seems to be broken (like it will warn almost every single time).

For example, is it possible or likely, that a human will want to set some value to something'somethingelse? If that is possible, then we should certainly add some escaping.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for pointing out this. I added validator for this.

func testAccConfigVarConfig_withInstanceAndType(varName string, varValue string, varType string, varInstance string) string {
return fmt.Sprintf(`
resource "mysql_ti_config" "test" {
name = "%s"
Copy link
Owner

Choose a reason for hiding this comment

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

Indent it please.

d.Set("value", defaultValue.String())

return CreateOrUpdateConfigVariable(d, meta)

Copy link
Owner

Choose a reason for hiding this comment

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

No newline after return, please.

Copy link
Author

Choose a reason for hiding this comment

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

👍

mysql/resource_ti_config_defaults.go Show resolved Hide resolved
mysql/resource_ti_config_variable.go Show resolved Hide resolved
mysql/resource_ti_config_variable_test.go Show resolved Hide resolved
mysql/resource_ti_config_variable_test.go Show resolved Hide resolved
mysql/resource_ti_config_variable_test.go Outdated Show resolved Hide resolved
configQuery = fmt.Sprintf("SET CONFIG \"%s\" %s=", varInstance, quoteIdentifier(varName))
}

if isNumeric(varValue) {
Copy link
Owner

Choose a reason for hiding this comment

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

This doesn't sound right. For DBs respecting data types, it depends on the type of key. Type of value may help (maybe that's your approximation), but it doesn't always work.

Doesn't TiDB respect it (like MySQL) in case you quote everything?

Copy link
Author

Choose a reason for hiding this comment

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

L64:
If instance is in place then it requires extra quoting like in the example
set config "127.0.0.1:20180" split.qps-threshold=1000

Everything else should be configured like this
set config tikv split.qps-threshold=1000

ref. https://docs.pingcap.com/tidb/stable/dynamic-config

Copy link
Owner

Choose a reason for hiding this comment

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

L64: If instance is in place then it requires extra quoting like in the example set config "127.0.0.1:20180" `split.qps-threshold`=1000

Everything else should be configured like this set config tikv `split.qps-threshold`=1000

We don't understand each other - is it bad, if you quote it like this?

set config tikv `split.qps-threshold`='1000'

I believe it would be also acceptable and it would make it a bit easier to understand, but I'd leave it up to you.

Copy link
Author

@boltandrke boltandrke Aug 18, 2022

Choose a reason for hiding this comment

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

Got it 😀 Thank you 👍
Removed obsolete code

boltandrke added a commit to boltandrke/terraform-provider-mysql that referenced this pull request Aug 15, 2022
@boltandrke boltandrke requested a review from petoju August 15, 2022 13:21
scripts/tidb-test-cluster.sh Show resolved Hide resolved
GNUmakefile Outdated
@@ -52,12 +54,21 @@ testpercona:
testtidb%:
$(MAKE) MYSQL_VERSION=$* MYSQL_PORT=34$(shell echo "$*" | tr -d '.') testtidb

testtidb:
-docker run --rm --name test-tidb$(MYSQL_VERSION) -d -p $(MYSQL_PORT):4000 pingcap/tidb:v$(MYSQL_VERSION)
bin/tiup:
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks, this looks good. There is a minor issue there and I have / already had few more questions (replying you considered those is good enough for me). After that is done, I can merge it.

@boltandrke
Copy link
Author

If I understood correctly, everything should be fixed now.
Before you merge it, let me cleanup branch with rebase. :)

Copy link
Owner

@petoju petoju left a comment

Choose a reason for hiding this comment

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

Looks good now - thanks.

I'm not merging it yet as you requested a rebase.

@boltandrke boltandrke force-pushed the feature/add-ti-resources branch from 80767d3 to 4297527 Compare August 19, 2022 06:38
@boltandrke
Copy link
Author

Thank you!🙏 Now its clean. All acceptance tests passed and we are 🟢 to merge it.
Its was pleasure to work with you 🙇‍♂️

@boltandrke boltandrke requested a review from petoju August 19, 2022 10:06
@petoju petoju merged commit a7b8c1f into petoju:master Aug 19, 2022
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.

3 participants