Skip to content

Commit 3406d66

Browse files
committed
chore: add cockroachdb 26.1 to the matrix
1 parent 1d65cbb commit 3406d66

File tree

4 files changed

+58
-26
lines changed

4 files changed

+58
-26
lines changed

.github/workflows/build-test.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ jobs:
262262
fail-fast: false
263263
matrix:
264264
datastore: ["crdb"]
265-
crdbversion: ["25.2.0", "25.3.0"]
265+
crdbversion:
266+
# the version many folks are on
267+
- "25.2.0"
268+
# the most recent version
269+
- "26.1.0"
266270
steps:
267271
- uses: "actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8" # v4.2.2
268272
if: |
@@ -297,7 +301,11 @@ jobs:
297301
fail-fast: false
298302
matrix:
299303
datastore: ["crdb"]
300-
crdbversion: ["25.2.0", "25.3.0"]
304+
crdbversion:
305+
# the version many folks are on
306+
- "25.2.0"
307+
# the most recent version
308+
- "26.1.0"
301309
steps:
302310
- uses: "actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8" # v4.2.2
303311
if: |

internal/datastore/crdb/crdb_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"net"
1818
"os"
1919
"path/filepath"
20+
"strings"
2021
"testing"
2122
"time"
2223

@@ -112,6 +113,15 @@ func TestCRDBDatastoreWithoutIntegrity(t *testing.T) {
112113
GCWindow(veryLargeGCWindow),
113114
WithAcquireTimeout(5*time.Second),
114115
))
116+
117+
t.Run("TestVersionReading", createDatastoreTest(
118+
b,
119+
// TODO
120+
VersionReadingTest,
121+
RevisionQuantization(0),
122+
GCWindow(veryLargeGCWindow),
123+
WithAcquireTimeout(5*time.Second),
124+
))
115125
}
116126

117127
type datastoreTestFunc func(t *testing.T, ds datastore.Datastore)
@@ -960,3 +970,32 @@ func TestRegisterPrometheusCollectors(t *testing.T) {
960970
require.NotNil(t, poolReadMetric)
961971
require.Equal(t, float64(readMaxConns), poolReadMetric.GetGauge().GetValue()) //nolint:testifylint // we expect exact values
962972
}
973+
974+
func VersionReadingTest(t *testing.T, rawDS datastore.Datastore) {
975+
require := require.New(t)
976+
977+
expectedVersionList := strings.Split(crdbTestVersion(), ".")
978+
expectedMajor := expectedVersionList[0]
979+
expectedMinor := expectedVersionList[1]
980+
expectedPatch := expectedVersionList[2]
981+
982+
const (
983+
readMaxConns = 10
984+
)
985+
// Set up a raw connection to the DB
986+
initPoolConfig, err := pgxpool.ParseConfig(fmt.Sprintf("postgres://db:password@pg.example.com:5432/mydb?pool_max_conns=%d", readMaxConns))
987+
require.NoError(err)
988+
initPool, err := pool.NewRetryPool(t.Context(), "read", initPoolConfig, nil, 18, 20)
989+
require.NoError(err)
990+
t.Cleanup(func() {
991+
initPool.Close()
992+
})
993+
994+
var version crdbVersion
995+
err = queryServerVersion(t.Context(), initPool, &version)
996+
require.NoError(err)
997+
998+
require.Equal(expectedMajor, version.Major)
999+
require.Equal(expectedMinor, version.Minor)
1000+
require.Equal(expectedPatch, version.Patch)
1001+
}

internal/datastore/crdb/version.go

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,33 @@ package crdb
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"regexp"
87
"strconv"
98

109
"github.com/jackc/pgx/v5"
11-
"github.com/jackc/pgx/v5/pgconn"
1210
"github.com/rs/zerolog"
1311

1412
pgxcommon "github.com/authzed/spicedb/internal/datastore/postgres/common"
1513
)
1614

1715
const (
18-
queryVersionJSON = "SELECT crdb_internal.active_version()::jsonb;"
19-
queryVersion = "SELECT version();"
20-
21-
errFunctionDoesNotExist = "42883"
16+
queryVersion = "SELECT version();"
2217
)
2318

2419
var versionRegex = regexp.MustCompile(`v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?`)
2520

21+
// queryServerVersion reads the version() string out of CRDB
22+
// and then parses it using a regex to determine the semver.
2623
func queryServerVersion(ctx context.Context, db pgxcommon.DBFuncQuerier, version *crdbVersion) error {
24+
var versionStr string
2725
if err := db.QueryRowFunc(ctx, func(ctx context.Context, row pgx.Row) error {
28-
return row.Scan(version)
29-
}, queryVersionJSON); err != nil {
30-
var pgerr *pgconn.PgError
31-
if !errors.As(err, &pgerr) || pgerr.Code != errFunctionDoesNotExist {
32-
return err
33-
}
34-
35-
// The crdb_internal.active_version() wasn't added until v22.1.X, try to parse the version
36-
var versionStr string
37-
if err := db.QueryRowFunc(ctx, func(ctx context.Context, row pgx.Row) error {
38-
return row.Scan(&versionStr)
39-
}, queryVersion); err != nil {
40-
return err
41-
}
42-
43-
return parseVersionStringInto(versionStr, version)
26+
return row.Scan(&versionStr)
27+
}, queryVersion); err != nil {
28+
return err
4429
}
4530

46-
return nil
31+
return parseVersionStringInto(versionStr, version)
4732
}
4833

4934
func parseVersionStringInto(versionStr string, version *crdbVersion) error {

internal/datastore/crdb/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ const MinimumSupportedCockroachDBVersion = "23.1.30"
88
// LatestTestedCockroachDBVersion is the latest version of CockroachDB that has been tested with this driver.
99
//
1010
// NOTE: must match a tag on DockerHub for the `cockroachdb/cockroach` image, without the `v` prefix.
11-
const LatestTestedCockroachDBVersion = "25.3.2"
11+
const LatestTestedCockroachDBVersion = "26.1.0"

0 commit comments

Comments
 (0)