Skip to content

Commit 7f82bf5

Browse files
committed
chore: add cockroachdb 26.1 to the matrix
1 parent 80b3228 commit 7f82bf5

File tree

6 files changed

+65
-31
lines changed

6 files changed

+65
-31
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@v6"
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@v6"
303311
if: |

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1212
### Changed
1313
- Begin deprecation of library "github.com/dlmiddlecote/sqlstats" (https://github.com/authzed/spicedb/pull/2904).
1414
NOTE: in a future release, MySQL metrics will change.
15+
- Added support for CRDB 26.1 by fixing how version information is read from the cluster
1516

1617
### Fixed
1718
- enforce graceful shutdown on serve and serve-testing (https://github.com/authzed/spicedb/pull/2888)

internal/datastore/crdb/crdb_test.go

Lines changed: 38 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,14 @@ func TestCRDBDatastoreWithoutIntegrity(t *testing.T) {
112113
GCWindow(veryLargeGCWindow),
113114
WithAcquireTimeout(5*time.Second),
114115
))
116+
117+
t.Run("TestVersionReading", createDatastoreTest(
118+
b,
119+
VersionReadingTest,
120+
RevisionQuantization(0),
121+
GCWindow(veryLargeGCWindow),
122+
WithAcquireTimeout(5*time.Second),
123+
))
115124
}
116125

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

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"

pkg/datastore/test/revisions.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020

2121
// RevisionQuantizationTest tests whether or not the requirements for revisions hold
2222
// for a particular datastore.
23-
// TODO: rewrite using synctest
2423
func RevisionQuantizationTest(t *testing.T, tester DatastoreTester) {
2524
testCases := []struct {
2625
quantizationRange time.Duration
@@ -178,6 +177,7 @@ func RevisionGCTest(t *testing.T, tester DatastoreTester) {
178177
time.Sleep(gcWindow)
179178

180179
gcable, ok := ds.(common.GarbageCollectableDatastore)
180+
// NOTE: CRDB and Spanner both do garbage collection with row-level TTLs
181181
if ok {
182182
// Run garbage collection.
183183
gcable.ResetGCCompleted()
@@ -198,9 +198,14 @@ func RevisionGCTest(t *testing.T, tester DatastoreTester) {
198198
// require.Error(err, "expected previously written schema to exist at out-of-GC window head")
199199

200200
// check freshly fetched head revision is valid after GC window elapsed
201-
head, err = ds.HeadRevision(ctx)
202201
require.NoError(err)
203202

203+
// assert that recent call to head revision is also valid, even after a GC window cycle without writes elapsed
204+
require.NoError(ds.CheckRevision(ctx, head), "expected freshly obtained head revision to be valid")
205+
206+
// TODO: these reads are taking a significant amount of time on CRDB, on the order
207+
// of 100ms for a row read. We need to ascertain whether this is a test artifact
208+
// or a performance regression.
204209
// check that we can read a caveat whose revision has been garbage collectged
205210
_, _, err = ds.SnapshotReader(head).LegacyReadCaveatByName(ctx, testCaveat.Name)
206211
require.NoError(err, "expected previously written caveat should exist at head")
@@ -213,9 +218,6 @@ func RevisionGCTest(t *testing.T, tester DatastoreTester) {
213218
_, _, err = ds.SnapshotReader(head).LegacyReadNamespaceByName(ctx, "foo/bar")
214219
require.NoError(err, "expected previously written schema to exist at head")
215220

216-
// and that recent call to head revision is also valid, even after a GC window cycle without writes elapsed
217-
require.NoError(ds.CheckRevision(ctx, head), "expected freshly obtained head revision to be valid")
218-
219221
// write happens, we get a new head revision
220222
newerRev, err := ds.ReadWriteTx(ctx, func(ctx context.Context, rwt datastore.ReadWriteTransaction) error {
221223
return rwt.LegacyWriteNamespaces(ctx, testNamespace)

0 commit comments

Comments
 (0)