Skip to content

Commit 2297338

Browse files
committed
Merge branch 'master' into CBG-3203
2 parents ae1b483 + e287e05 commit 2297338

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2857
-2721
lines changed

.github/workflows/ci.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- uses: actions/checkout@v3
2828
- uses: actions/setup-go@v4
2929
with:
30-
go-version: 1.21.3
30+
go-version: 1.21.4
3131
- name: go-build
3232
run: go build "./..."
3333

@@ -38,7 +38,7 @@ jobs:
3838
- uses: actions/checkout@v3
3939
- uses: actions/setup-go@v4
4040
with:
41-
go-version: 1.21.3
41+
go-version: 1.21.4
4242
- run: go install github.com/google/addlicense@latest
4343
- run: addlicense -check -f licenses/addlicense.tmpl .
4444

@@ -49,13 +49,13 @@ jobs:
4949
- uses: actions/checkout@v3
5050
- uses: actions/setup-go@v4
5151
with:
52-
go-version: 1.21.3
52+
go-version: 1.21.4
5353
cache: false
5454
- name: golangci-lint
5555
uses: golangci/golangci-lint-action@v3
5656
with:
57-
version: v1.55.0
58-
args: --config=.golangci-strict.yml --timeout=3m
57+
version: v1.55.2
58+
args: --config=.golangci-strict.yml
5959

6060
test:
6161
runs-on: ${{ matrix.os }}
@@ -77,7 +77,7 @@ jobs:
7777
- uses: actions/checkout@v3
7878
- uses: actions/setup-go@v4
7979
with:
80-
go-version: 1.21.3
80+
go-version: 1.21.4
8181
- name: Build
8282
run: go build -v "./..."
8383
- name: Run Tests
@@ -97,7 +97,7 @@ jobs:
9797
- uses: actions/checkout@v3
9898
- uses: actions/setup-go@v4
9999
with:
100-
go-version: 1.21.3
100+
go-version: 1.21.4
101101
- name: Run Tests
102102
run: go test -race -timeout=30m -count=1 -json -v "./..." | tee test.json | jq -s -jr 'sort_by(.Package,.Time) | .[].Output | select (. != null )'
103103
shell: bash
@@ -137,7 +137,7 @@ jobs:
137137
- uses: actions/checkout@v3
138138
- uses: actions/setup-go@v4
139139
with:
140-
go-version: 1.21.3
140+
go-version: 1.21.4
141141
- name: Build
142142
run: go build -v "./tools/stats-definition-exporter"
143143
- name: Run Tests

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ __pycache__
2121

2222
### Couchbase Plugin ###
2323
.cbcache/
24+
25+
planPIndexes/

.golangci-strict.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
# config file for golangci-lint
1010

11+
run:
12+
timeout: 3m
13+
1114
linters:
1215
enable:
1316
#- bodyclose # checks whether HTTP response body is closed successfully
@@ -24,7 +27,7 @@ linters:
2427
#- nakedret # Finds naked returns in functions greater than a specified function length
2528
#- prealloc # Finds slice declarations that could potentially be preallocated
2629
#- revive # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
27-
#- staticcheck # (megacheck) Staticcheck is a go vet on steroids, applying a ton of static analysis checks
30+
- staticcheck # (megacheck) Staticcheck is a go vet on steroids, applying a ton of static analysis checks
2831
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
2932
- unconvert # Remove unnecessary type conversions
3033
#- unparam # Reports unused function parameters
@@ -67,7 +70,6 @@ linters:
6770
- nakedret # Finds naked returns in functions greater than a specified function length
6871
- prealloc # Finds slice declarations that could potentially be preallocated
6972
- revive # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
70-
- staticcheck # (megacheck) Staticcheck is a go vet on steroids, applying a ton of static analysis checks
7173
- structcheck # Finds unused struct fields
7274
- unparam # Reports unused function parameters
7375
- varcheck # Finds unused global variables and constants

.golangci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
# config file for golangci-lint
1010

11+
run:
12+
timeout: 3m
13+
1114
linters:
1215
enable:
1316
- bodyclose # checks whether HTTP response body is closed successfully

Jenkinsfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pipeline {
1616
}
1717

1818
tools {
19-
go '1.21.3'
19+
go '1.21.4'
2020
}
2121

2222
stages {

auth/auth_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ func TestConcurrentUserWrites(t *testing.T) {
721721
}
722722

723723
// Retrieve user to trigger initial calculation of roles, channels
724-
user, getErr := auth.GetUser(username)
724+
_, getErr := auth.GetUser(username)
725725
require.NoError(t, getErr, "Error retrieving user")
726726

727727
require.NoError(t, auth.SetBcryptCost(DefaultBcryptCost))

auth/oidc_test.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -1205,9 +1205,8 @@ func TestJWTRolesChannels(t *testing.T) {
12051205

12061206
for i, login := range tc.logins {
12071207
var (
1208-
user User
1209-
err error
1210-
lastUpdateTime time.Time
1208+
user User
1209+
err error
12111210
)
12121211
if i == 0 {
12131212
user, err = auth.NewUser(testUserPrefix+"_"+testSubject, "test", base.SetFromArray(login.explicitChannels))
@@ -1254,8 +1253,6 @@ func TestJWTRolesChannels(t *testing.T) {
12541253
}
12551254
require.Equal(t, base.SetFromArray(login.expectedChannels), user.Channels().AsSet())
12561255

1257-
require.Greater(t, user.JWTLastUpdated(), lastUpdateTime)
1258-
lastUpdateTime = user.JWTLastUpdated()
12591256
}
12601257
})
12611258
}

auth/password_hash_test.go

+16-13
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,30 @@ func BenchmarkBcryptCostTimes(b *testing.B) {
3535

3636
for i := minCostToTest; i < maxCostToTest; i++ {
3737
b.Run(fmt.Sprintf("cost%d", i), func(bn *testing.B) {
38-
bn.N = 1
3938
_, err := bcrypt.GenerateFromPassword([]byte("hunter2"), i)
4039
assert.NoError(bn, err)
4140
})
4241
}
4342
}
4443

45-
// TestBcryptDefaultCostTime will ensure that the default bcrypt cost takes at least a 'reasonable' amount of time
46-
// If this test fails, it suggests maybe we need to think about increasing the default cost...
47-
func TestBcryptDefaultCostTime(t *testing.T) {
48-
// Modest 2.2GHz macbook i7 takes ~80ms at cost 10
49-
// Assume server CPUs are ~2x faster
50-
minimumDuration := 40 * time.Millisecond
44+
// TestBcryptCostTimes will output the time it takes to hash a password with each bcrypt cost value
45+
func TestBcryptCostTimes(t *testing.T) {
46+
// Little value in running this regularly. Might be useful for one-off informational purposes
47+
t.Skip("Test disabled")
5148

52-
startTime := time.Now()
53-
_, err := bcrypt.GenerateFromPassword([]byte("hunter2"), DefaultBcryptCost)
54-
duration := time.Since(startTime)
49+
minCostToTest := bcrypt.DefaultCost
50+
maxCostToTest := bcrypt.DefaultCost + 5
5551

56-
t.Logf("bcrypt.GenerateFromPassword with cost %d took: %v", DefaultBcryptCost, duration)
57-
assert.NoError(t, err)
58-
assert.True(t, minimumDuration < duration)
52+
for i := minCostToTest; i < maxCostToTest; i++ {
53+
t.Run(fmt.Sprintf("cost%d", i), func(t *testing.T) {
54+
startTime := time.Now()
55+
_, err := bcrypt.GenerateFromPassword([]byte("hunter2"), i)
56+
duration := time.Since(startTime)
57+
58+
t.Logf("bcrypt.GenerateFromPassword with cost %d took: %v", i, duration)
59+
assert.NoError(t, err)
60+
})
61+
}
5962
}
6063

6164
func TestSetBcryptCost(t *testing.T) {

base/collection.go

-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ func GetGoCBv2Bucket(ctx context.Context, spec BucketSpec) (*GocbV2Bucket, error
6363
RetryStrategy: gocb.NewBestEffortRetryStrategy(nil),
6464
}
6565

66-
if spec.KvPoolSize > 0 {
67-
// TODO: Equivalent of kvPoolSize in gocb v2?
68-
}
69-
7066
cluster, err := gocb.Connect(connString, clusterOptions)
7167
if err != nil {
7268
InfofCtx(ctx, KeyAuth, "Unable to connect to cluster: %v", err)

base/dcp_sharded.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const DefaultImportPartitions = 16
2828
const DefaultImportPartitionsServerless = 6
2929

3030
// firstVersionToSupportCollections represents the earliest Sync Gateway release that supports collections.
31-
var firstVersionToSupportCollections = &ComparableVersion{
31+
var firstVersionToSupportCollections = &ComparableBuildVersion{
3232
epoch: 0,
3333
major: 3,
3434
minor: 1,
@@ -38,7 +38,7 @@ var firstVersionToSupportCollections = &ComparableVersion{
3838
// nodeExtras is the contents of the JSON value of the cbgt.NodeDef.Extras field as used by Sync Gateway.
3939
type nodeExtras struct {
4040
// Version is the node's version.
41-
Version *ComparableVersion `json:"v"`
41+
Version *ComparableBuildVersion `json:"v"`
4242
}
4343

4444
// CbgtContext holds the two handles we have for CBGT-related functionality.
@@ -376,7 +376,7 @@ func (c *CbgtContext) StartManager(ctx context.Context, dbName string, configGro
376376

377377
// getNodeVersion returns the version of the node from its Extras field, or nil if none is stored. Returns an error if
378378
// the extras could not be parsed.
379-
func getNodeVersion(def *cbgt.NodeDef) (*ComparableVersion, error) {
379+
func getNodeVersion(def *cbgt.NodeDef) (*ComparableBuildVersion, error) {
380380
if len(def.Extras) == 0 {
381381
return nil, nil
382382
}
@@ -388,7 +388,7 @@ func getNodeVersion(def *cbgt.NodeDef) (*ComparableVersion, error) {
388388
}
389389

390390
// getMinNodeVersion returns the version of the oldest node currently in the cluster.
391-
func getMinNodeVersion(cfg cbgt.Cfg) (*ComparableVersion, error) {
391+
func getMinNodeVersion(cfg cbgt.Cfg) (*ComparableBuildVersion, error) {
392392
nodes, _, err := cbgt.CfgGetNodeDefs(cfg, cbgt.NODE_DEFS_KNOWN)
393393
if err != nil {
394394
return nil, err
@@ -397,14 +397,14 @@ func getMinNodeVersion(cfg cbgt.Cfg) (*ComparableVersion, error) {
397397
// If there are no nodes at all, it's likely we're the first node in the cluster.
398398
return ProductVersion, nil
399399
}
400-
var minVersion *ComparableVersion
400+
var minVersion *ComparableBuildVersion
401401
for _, node := range nodes.NodeDefs {
402402
nodeVersion, err := getNodeVersion(node)
403403
if err != nil {
404404
return nil, fmt.Errorf("failed to get version of node %v: %w", MD(node.HostPort).Redact(), err)
405405
}
406406
if nodeVersion == nil {
407-
nodeVersion = zeroComparableVersion()
407+
nodeVersion = zeroComparableBuildVersion()
408408
}
409409
if minVersion == nil || nodeVersion.Less(minVersion) {
410410
minVersion = nodeVersion
@@ -678,11 +678,11 @@ func (meh *sgMgrEventHandlers) OnUnregisterPIndex(pindex *cbgt.PIndex) {
678678
// OnFeedError is required to trigger reconnection to a feed on a closed connection (EOF).
679679
// NotifyMgrOnClose will trigger cbgt closing and then attempt to reconnect to the feed, if the manager hasn't
680680
// been stopped.
681-
func (meh *sgMgrEventHandlers) OnFeedError(srcType string, r cbgt.Feed, feedErr error) {
681+
func (meh *sgMgrEventHandlers) OnFeedError(_ string, r cbgt.Feed, feedErr error) {
682682

683683
// cbgt always passes srcType = SOURCE_GOCBCORE, but we have a wrapped type associated with our indexes - use that instead
684684
// for our logging
685-
srcType = SOURCE_DCP_SG
685+
srcType := SOURCE_DCP_SG
686686
var bucketName, bucketUUID string
687687
dcpFeed, ok := r.(cbgt.FeedEx)
688688
if ok {

base/leaky_bucket.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ func (b *LeakyBucket) SetIgnoreClose(value bool) {
5858
b.config.IgnoreClose = value
5959
}
6060

61-
func (b *LeakyBucket) CloseAndDelete() error {
61+
func (b *LeakyBucket) CloseAndDelete(ctx context.Context) error {
6262
if bucket, ok := b.bucket.(sgbucket.DeleteableStore); ok {
63-
return bucket.CloseAndDelete()
63+
return bucket.CloseAndDelete(ctx)
6464
}
6565
return nil
6666
}
@@ -358,8 +358,7 @@ func dedupeTapEvents(tapEvents []sgbucket.FeedEvent) []sgbucket.FeedEvent {
358358
// sequence order as read off the feed.
359359
deduped := []sgbucket.FeedEvent{}
360360
for _, tapEvent := range tapEvents {
361-
key := string(tapEvent.Key)
362-
latestTapEventForKey := latestTapEventPerKey[key]
361+
latestTapEventForKey := latestTapEventPerKey[string(tapEvent.Key)]
363362
if tapEvent.Cas == latestTapEventForKey.Cas {
364363
deduped = append(deduped, tapEvent)
365364
}

base/logger_external.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ func initExternalLoggers() {
4646
}
4747

4848
func updateExternalLoggers() {
49-
if consoleLogger != nil && consoleLogger.shouldLog(nil, LevelDebug, KeyWalrus) {
49+
// use context.Background() since this is called from init or to reset test logging
50+
if consoleLogger != nil && consoleLogger.shouldLog(context.Background(), LevelDebug, KeyWalrus) {
5051
rosmar.SetLogLevel(rosmar.LevelDebug)
5152
} else {
5253
rosmar.SetLogLevel(rosmar.LevelInfo)

base/logging_test.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ package base
1111
import (
1212
"bytes"
1313
"fmt"
14-
"math/rand"
1514
"os"
1615
"path/filepath"
1716
"runtime"
@@ -79,9 +78,7 @@ func BenchmarkLogRotation(b *testing.B) {
7978

8079
for _, test := range tests {
8180
b.Run(fmt.Sprintf("rotate:%t-compress:%t-bytes:%v", test.rotate, test.compress, test.numBytes), func(bm *testing.B) {
82-
data := make([]byte, test.numBytes)
83-
_, err := rand.Read(data)
84-
require.NoError(bm, err)
81+
data := FastRandBytes(bm, test.numBytes)
8582

8683
logPath := b.TempDir()
8784
logger := lumberjack.Logger{Filename: filepath.Join(logPath, "output.log"), Compress: test.compress}
@@ -99,7 +96,7 @@ func BenchmarkLogRotation(b *testing.B) {
9996
// we can't remove temp dir while the async compression is still writing log files
10097
assert.NoError(bm, logger.Close())
10198
ctx := TestCtx(bm)
102-
err, _ = RetryLoop(ctx, "benchmark-logrotate-teardown",
99+
err, _ := RetryLoop(ctx, "benchmark-logrotate-teardown",
103100
func() (shouldRetry bool, err error, value interface{}) {
104101
err = os.RemoveAll(logPath)
105102
return err != nil, err, nil

base/main_test_bucket_pool.go

+6-22
Original file line numberDiff line numberDiff line change
@@ -198,29 +198,17 @@ func (tbp *TestBucketPool) GetWalrusTestBucket(t testing.TB, url string) (b Buck
198198
require.NoError(t, err)
199199

200200
var walrusBucket *rosmar.Bucket
201-
var typeName string
201+
const typeName = "rosmar"
202202
bucketName := tbpBucketNamePrefix + "rosmar_" + id
203203
if url == "walrus:" || url == rosmar.InMemoryURL {
204-
walrusBucket, err = rosmar.OpenBucket(url, rosmar.CreateOrOpen)
205-
if err == nil {
206-
err := walrusBucket.SetName(bucketName)
207-
if err != nil {
208-
tbp.Fatalf(testCtx, "Could not set name %s for rosmar bucket: %s", bucketName, err)
209-
}
210-
}
204+
walrusBucket, err = rosmar.OpenBucket(url, bucketName, rosmar.CreateOrOpen)
211205
} else {
212206
walrusBucket, err = rosmar.OpenBucketIn(url, bucketName, rosmar.CreateOrOpen)
213207
}
214-
typeName = "rosmar"
215208
if err != nil {
216209
tbp.Fatalf(testCtx, "couldn't get %s bucket from <%s>: %v", typeName, url, err)
217210
}
218211

219-
err = walrusBucket.SetName(bucketName)
220-
if err != nil {
221-
tbp.Fatalf(testCtx, "Could not set name %s for rosmar bucket: %s", bucketName, err)
222-
}
223-
224212
// Wrap Walrus buckets with a leaky bucket to support vbucket IDs on feed.
225213
b = &LeakyBucket{bucket: walrusBucket, config: &LeakyBucketConfig{TapFeedVbuckets: true}}
226214

@@ -258,14 +246,10 @@ func (tbp *TestBucketPool) GetWalrusTestBucket(t testing.TB, url string) (b Buck
258246
atomic.AddInt32(&tbp.stats.NumBucketsClosed, 1)
259247
atomic.AddInt64(&tbp.stats.TotalInuseBucketNano, time.Since(openedStart).Nanoseconds())
260248
tbp.markBucketClosed(t, b)
261-
if url == kTestWalrusURL {
262-
b.Close(ctx)
263-
} else {
264-
// Persisted buckets should call close and delete
265-
closeErr := walrusBucket.CloseAndDelete()
266-
if closeErr != nil {
267-
tbp.Logf(ctx, "Unexpected error closing persistent %s bucket: %v", typeName, closeErr)
268-
}
249+
// Persisted buckets should call close and delete
250+
closeErr := walrusBucket.CloseAndDelete(ctx)
251+
if closeErr != nil {
252+
tbp.Logf(ctx, "Unexpected error closing persistent %s bucket: %v", typeName, closeErr)
269253
}
270254

271255
}

0 commit comments

Comments
 (0)