Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit 46902e5

Browse files
0x1a8510f2devonh
andauthored
Take advantage of changes in recent Go versions (#3361)
Given that #2714 wasn't merged but we are now at a minimum supported Go version of 1.20 (soon to be 1.21), I wanted to carry over some of the changes. Namely: - Fix the log typo - Simplify build constraints for unix - Use stdlib atomic package ### Pull Request Checklist <!-- Please read https://matrix-org.github.io/dendrite/development/contributing before submitting your pull request --> * [x] I have added Go unit tests or [Complement integration tests](https://github.com/matrix-org/complement) for this PR _or_ I have justified why this PR doesn't need tests * [x] Pull request includes a [sign off below using a legally identifiable name](https://matrix-org.github.io/dendrite/development/contributing#sign-off) _or_ I have already signed off privately Signed-off-by: `0x1a8510f2 <admin@0x1a8510f2.space>` --------- Co-authored-by: devonh <devon.dmytro@gmail.com>
1 parent 5547bf8 commit 46902e5

File tree

10 files changed

+23
-24
lines changed

10 files changed

+23
-24
lines changed

clientapi/routing/routing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func Setup(
255255
logrus.Info("Enabling server notices at /_synapse/admin/v1/send_server_notice")
256256
serverNotificationSender, err := getSenderDevice(context.Background(), rsAPI, userAPI, cfg)
257257
if err != nil {
258-
logrus.WithError(err).Fatal("unable to get account for sending sending server notices")
258+
logrus.WithError(err).Fatal("unable to get account for sending server notices")
259259
}
260260

261261
synapseAdminRouter.Handle("/admin/v1/send_server_notice/{txnID}",

cmd/dendrite-demo-pinecone/relay/retriever.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ package relay
1717
import (
1818
"context"
1919
"sync"
20+
"sync/atomic"
2021
"time"
2122

2223
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
2324
relayServerAPI "github.com/matrix-org/dendrite/relayapi/api"
2425
"github.com/matrix-org/gomatrixserverlib/spec"
2526
"github.com/sirupsen/logrus"
26-
"go.uber.org/atomic"
2727
)
2828

2929
const (
@@ -54,7 +54,7 @@ func NewRelayServerRetriever(
5454
federationAPI: federationAPI,
5555
relayAPI: relayAPI,
5656
relayServersQueried: make(map[spec.ServerName]bool),
57-
running: *atomic.NewBool(false),
57+
running: atomic.Bool{},
5858
quit: quit,
5959
}
6060
}

federationapi/queue/destinationqueue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import (
1919
"encoding/json"
2020
"fmt"
2121
"sync"
22+
"sync/atomic"
2223
"time"
2324

2425
"github.com/matrix-org/gomatrix"
2526
"github.com/matrix-org/gomatrixserverlib"
2627
"github.com/matrix-org/gomatrixserverlib/fclient"
2728
"github.com/matrix-org/gomatrixserverlib/spec"
2829
"github.com/sirupsen/logrus"
29-
"go.uber.org/atomic"
3030

3131
"github.com/matrix-org/dendrite/federationapi/statistics"
3232
"github.com/matrix-org/dendrite/federationapi/storage"

federationapi/queue/queue_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"encoding/json"
2020
"fmt"
21+
"sync/atomic"
2122
"testing"
2223
"time"
2324

@@ -26,7 +27,6 @@ import (
2627
"github.com/matrix-org/dendrite/test/testrig"
2728
"github.com/matrix-org/gomatrixserverlib/fclient"
2829
"github.com/matrix-org/gomatrixserverlib/spec"
29-
"go.uber.org/atomic"
3030
"gotest.tools/v3/poll"
3131

3232
"github.com/matrix-org/gomatrixserverlib"
@@ -113,8 +113,8 @@ func testSetup(failuresUntilBlacklist uint32, failuresUntilAssumedOffline uint32
113113
fc := &stubFederationClient{
114114
shouldTxSucceed: shouldTxSucceed,
115115
shouldTxRelaySucceed: shouldTxRelaySucceed,
116-
txCount: *atomic.NewUint32(0),
117-
txRelayCount: *atomic.NewUint32(0),
116+
txCount: atomic.Uint32{},
117+
txRelayCount: atomic.Uint32{},
118118
}
119119

120120
stats := statistics.NewStatistics(db, failuresUntilBlacklist, failuresUntilAssumedOffline, false)

federationapi/statistics/statistics.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"math"
66
"math/rand"
77
"sync"
8+
"sync/atomic"
89
"time"
910

1011
"github.com/sirupsen/logrus"
11-
"go.uber.org/atomic"
1212

1313
"github.com/matrix-org/dendrite/federationapi/storage"
1414
"github.com/matrix-org/gomatrixserverlib/spec"
@@ -169,7 +169,7 @@ func (s *ServerStatistics) Success(method SendMethod) {
169169
// NOTE : Sending to the final destination vs. a relay server has
170170
// slightly different semantics.
171171
if method == SendDirect {
172-
s.successCounter.Inc()
172+
s.successCounter.Add(1)
173173
if s.blacklisted.Load() && s.statistics.DB != nil {
174174
if err := s.statistics.DB.RemoveServerFromBlacklist(s.serverName); err != nil {
175175
logrus.WithError(err).Errorf("Failed to remove %q from blacklist", s.serverName)
@@ -195,7 +195,7 @@ func (s *ServerStatistics) Failure() (time.Time, bool) {
195195
// start a goroutine which will wait out the backoff and
196196
// unset the backoffStarted flag when done.
197197
if s.backoffStarted.CompareAndSwap(false, true) {
198-
backoffCount := s.backoffCount.Inc()
198+
backoffCount := s.backoffCount.Add(1)
199199

200200
if backoffCount >= s.statistics.FailuresUntilAssumedOffline {
201201
s.assumedOffline.CompareAndSwap(false, true)

internal/sqlutil/writer_exclusive.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package sqlutil
33
import (
44
"database/sql"
55
"errors"
6-
7-
"go.uber.org/atomic"
6+
"sync/atomic"
87
)
98

109
// ExclusiveWriter implements sqlutil.Writer.

internal/transactionrequest_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import (
1919
"encoding/json"
2020
"fmt"
2121
"strconv"
22+
"sync/atomic"
2223
"testing"
2324
"time"
2425

2526
"github.com/matrix-org/gomatrixserverlib"
2627
"github.com/matrix-org/gomatrixserverlib/spec"
2728
"github.com/nats-io/nats.go"
2829
"github.com/stretchr/testify/assert"
29-
"go.uber.org/atomic"
3030
"gotest.tools/v3/poll"
3131

3232
"github.com/matrix-org/dendrite/federationapi/producers"
@@ -228,7 +228,7 @@ func TestProcessTransactionRequestEDUTyping(t *testing.T) {
228228
ctx := process.NewProcessContext()
229229
defer ctx.ShutdownDendrite()
230230
txn, js, cfg := createTransactionWithEDU(ctx, edus)
231-
received := atomic.NewBool(false)
231+
received := atomic.Bool{}
232232
onMessage := func(ctx context.Context, msgs []*nats.Msg) bool {
233233
msg := msgs[0] // Guaranteed to exist if onMessage is called
234234
room := msg.Header.Get(jetstream.RoomID)
@@ -294,7 +294,7 @@ func TestProcessTransactionRequestEDUToDevice(t *testing.T) {
294294
ctx := process.NewProcessContext()
295295
defer ctx.ShutdownDendrite()
296296
txn, js, cfg := createTransactionWithEDU(ctx, edus)
297-
received := atomic.NewBool(false)
297+
received := atomic.Bool{}
298298
onMessage := func(ctx context.Context, msgs []*nats.Msg) bool {
299299
msg := msgs[0] // Guaranteed to exist if onMessage is called
300300

@@ -371,7 +371,7 @@ func TestProcessTransactionRequestEDUDeviceListUpdate(t *testing.T) {
371371
ctx := process.NewProcessContext()
372372
defer ctx.ShutdownDendrite()
373373
txn, js, cfg := createTransactionWithEDU(ctx, edus)
374-
received := atomic.NewBool(false)
374+
received := atomic.Bool{}
375375
onMessage := func(ctx context.Context, msgs []*nats.Msg) bool {
376376
msg := msgs[0] // Guaranteed to exist if onMessage is called
377377

@@ -468,7 +468,7 @@ func TestProcessTransactionRequestEDUReceipt(t *testing.T) {
468468
ctx := process.NewProcessContext()
469469
defer ctx.ShutdownDendrite()
470470
txn, js, cfg := createTransactionWithEDU(ctx, edus)
471-
received := atomic.NewBool(false)
471+
received := atomic.Bool{}
472472
onMessage := func(ctx context.Context, msgs []*nats.Msg) bool {
473473
msg := msgs[0] // Guaranteed to exist if onMessage is called
474474

@@ -512,7 +512,7 @@ func TestProcessTransactionRequestEDUSigningKeyUpdate(t *testing.T) {
512512
ctx := process.NewProcessContext()
513513
defer ctx.ShutdownDendrite()
514514
txn, js, cfg := createTransactionWithEDU(ctx, edus)
515-
received := atomic.NewBool(false)
515+
received := atomic.Bool{}
516516
onMessage := func(ctx context.Context, msgs []*nats.Msg) bool {
517517
msg := msgs[0] // Guaranteed to exist if onMessage is called
518518

@@ -569,7 +569,7 @@ func TestProcessTransactionRequestEDUPresence(t *testing.T) {
569569
ctx := process.NewProcessContext()
570570
defer ctx.ShutdownDendrite()
571571
txn, js, cfg := createTransactionWithEDU(ctx, edus)
572-
received := atomic.NewBool(false)
572+
received := atomic.Bool{}
573573
onMessage := func(ctx context.Context, msgs []*nats.Msg) bool {
574574
msg := msgs[0] // Guaranteed to exist if onMessage is called
575575

setup/base/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ import (
2828
_ "net/http/pprof"
2929
"os"
3030
"os/signal"
31+
"sync/atomic"
3132
"syscall"
3233
"time"
3334

3435
sentryhttp "github.com/getsentry/sentry-go/http"
3536
"github.com/matrix-org/gomatrixserverlib/fclient"
3637
"github.com/prometheus/client_golang/prometheus/promhttp"
37-
"go.uber.org/atomic"
3838

3939
"github.com/gorilla/mux"
4040
"github.com/kardianos/minwinsvc"

setup/base/sanity_other.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !linux && !darwin && !netbsd && !freebsd && !openbsd && !solaris && !dragonfly && !aix
2-
// +build !linux,!darwin,!netbsd,!freebsd,!openbsd,!solaris,!dragonfly,!aix
1+
//go:build !unix
2+
// +build !unix
33

44
package base
55

setup/base/sanity_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build linux || darwin || netbsd || freebsd || openbsd || solaris || dragonfly || aix
2-
// +build linux darwin netbsd freebsd openbsd solaris dragonfly aix
1+
//go:build unix
2+
// +build unix
33

44
package base
55

0 commit comments

Comments
 (0)