This is an automated email from the ASF dual-hosted git repository. joaoreis pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/cassandra-gocql-driver.git
The following commit(s) were added to refs/heads/trunk by this push: new 4ad7479 Cassandra version unmarshal fix 4ad7479 is described below commit 4ad7479729a7fabcf3bf2e8126c6695ba719bf4c Author: tengu-alt <olexandr.luzh...@gmail.com> AuthorDate: Fri Jan 31 12:29:26 2025 +0200 Cassandra version unmarshal fix FIx for the issue, when the driver is unable to unmarshal Cassandra version, which contains additional annotation (suffix). patch by Oleksandr Luzhniy; reviewed by João Reis, James Hartig, Danylo Savchenko, for CASSGO-49 --- CHANGELOG.md | 1 + host_source.go | 25 +++++++++++++++++++++++-- host_source_test.go | 27 ++++++++++++++++++--------- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0055bf..72945a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Standardized spelling of datacenter (CASSGO-35) ### Fixed +- Cassandra version unmarshal fix (CASSGO-49) - Retry policy now takes into account query idempotency (CASSGO-27) diff --git a/host_source.go b/host_source.go index 1aebc3b..2be9e3a 100644 --- a/host_source.go +++ b/host_source.go @@ -58,6 +58,7 @@ const ( type cassVersion struct { Major, Minor, Patch int + Qualifier string } func (c *cassVersion) Set(v string) error { @@ -89,13 +90,30 @@ func (c *cassVersion) unmarshal(data []byte) error { c.Minor, err = strconv.Atoi(v[1]) if err != nil { - return fmt.Errorf("invalid minor version %v: %v", v[1], err) + vMinor := strings.Split(v[1], "-") + if len(vMinor) < 2 { + return fmt.Errorf("invalid minor version %v: %v", v[1], err) + } + c.Minor, err = strconv.Atoi(vMinor[0]) + if err != nil { + return fmt.Errorf("invalid minor version %v: %v", v[1], err) + } + c.Qualifier = v[1][strings.Index(v[1], "-")+1:] + return nil } if len(v) > 2 { c.Patch, err = strconv.Atoi(v[2]) if err != nil { - return fmt.Errorf("invalid patch version %v: %v", v[2], err) + vPatch := strings.Split(v[2], "-") + if len(vPatch) < 2 { + return fmt.Errorf("invalid patch version %v: %v", v[2], err) + } + c.Patch, err = strconv.Atoi(vPatch[0]) + if err != nil { + return fmt.Errorf("invalid patch version %v: %v", v[2], err) + } + c.Qualifier = v[2][strings.Index(v[2], "-")+1:] } } @@ -122,6 +140,9 @@ func (c cassVersion) AtLeast(major, minor, patch int) bool { } func (c cassVersion) String() string { + if c.Qualifier != "" { + return fmt.Sprintf("%d.%d.%d-%v", c.Major, c.Minor, c.Patch, c.Qualifier) + } return fmt.Sprintf("v%d.%d.%d", c.Major, c.Minor, c.Patch) } diff --git a/host_source_test.go b/host_source_test.go index 0813842..cd4dfc0 100644 --- a/host_source_test.go +++ b/host_source_test.go @@ -29,6 +29,7 @@ package gocql import ( "errors" + "fmt" "net" "sync" "sync/atomic" @@ -41,9 +42,13 @@ func TestUnmarshalCassVersion(t *testing.T) { data string version cassVersion }{ - {"3.2", cassVersion{3, 2, 0}}, - {"2.10.1-SNAPSHOT", cassVersion{2, 10, 1}}, - {"1.2.3", cassVersion{1, 2, 3}}, + {"3.2", cassVersion{3, 2, 0, ""}}, + {"2.10.1-SNAPSHOT", cassVersion{2, 10, 1, ""}}, + {"1.2.3", cassVersion{1, 2, 3, ""}}, + {"4.0-rc2", cassVersion{4, 0, 0, "rc2"}}, + {"4.3.2-rc1", cassVersion{4, 3, 2, "rc1"}}, + {"4.3.2-rc1-qualifier1", cassVersion{4, 3, 2, "rc1-qualifier1"}}, + {"4.3-rc1-qualifier1", cassVersion{4, 3, 0, "rc1-qualifier1"}}, } for i, test := range tests { @@ -53,6 +58,7 @@ func TestUnmarshalCassVersion(t *testing.T) { } else if *v != test.version { t.Errorf("%d: expected %#+v got %#+v", i, test.version, *v) } + fmt.Println(v.String()) } } @@ -60,14 +66,17 @@ func TestCassVersionBefore(t *testing.T) { tests := [...]struct { version cassVersion major, minor, patch int + Qualifier string }{ - {cassVersion{1, 0, 0}, 0, 0, 0}, - {cassVersion{0, 1, 0}, 0, 0, 0}, - {cassVersion{0, 0, 1}, 0, 0, 0}, + {cassVersion{1, 0, 0, ""}, 0, 0, 0, ""}, + {cassVersion{0, 1, 0, ""}, 0, 0, 0, ""}, + {cassVersion{0, 0, 1, ""}, 0, 0, 0, ""}, - {cassVersion{1, 0, 0}, 0, 1, 0}, - {cassVersion{0, 1, 0}, 0, 0, 1}, - {cassVersion{4, 1, 0}, 3, 1, 2}, + {cassVersion{1, 0, 0, ""}, 0, 1, 0, ""}, + {cassVersion{0, 1, 0, ""}, 0, 0, 1, ""}, + {cassVersion{4, 1, 0, ""}, 3, 1, 2, ""}, + + {cassVersion{4, 1, 0, ""}, 3, 1, 2, ""}, } for i, test := range tests { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org