Skip to content

Commit 7fe8106

Browse files
committed
Enable fieldalignment linter
1. Enable it 2. Run `make fix` 3. Bring back comments
1 parent 44d2451 commit 7fe8106

36 files changed

+818
-974
lines changed

.golangci.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
version: "2"
22

3-
issues:
4-
max-same-issues: 50
5-
63
formatters:
74
enable:
85
- goimports
@@ -17,6 +14,13 @@ formatters:
1714
max-len: 120
1815

1916
linters:
17+
exclusions:
18+
rules:
19+
- path: '(.+)_test\.go'
20+
text: "fieldalignment"
21+
linters:
22+
- govet
23+
2024
default: none
2125
enable:
2226
- nolintlint
@@ -26,7 +30,6 @@ linters:
2630
enable-all: true
2731
disable:
2832
- shadow
29-
- fieldalignment
3033

3134
nolintlint:
3235
allow-no-explanation: [ golines ]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ BIN_DIR := "${MAKEFILE_PATH}/bin"
55

66
CASSANDRA_VERSION ?= 4.1.6
77
SCYLLA_VERSION ?= release:6.1.1
8-
GOLANGCI_VERSION = 2.1.6
8+
GOLANGCI_VERSION = 2.4.0
99

1010
TEST_CQL_PROTOCOL ?= 4
1111
TEST_COMPRESSOR ?= snappy

cluster.go

Lines changed: 127 additions & 177 deletions
Large diffs are not rendered by default.

common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func addSslOptions(cluster *ClusterConfig) *ClusterConfig {
7575
}
7676

7777
type OnceManager struct {
78-
mu sync.Mutex
7978
keyspaces map[string]*sync.Once
79+
mu sync.Mutex
8080
}
8181

8282
func NewOnceManager() *OnceManager {

conn.go

Lines changed: 59 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,19 @@ type SslOptions struct {
140140
}
141141

142142
type ConnConfig struct {
143-
ProtoVersion int
144-
CQLVersion string
145-
WriteTimeout time.Duration
146-
ReadTimeout time.Duration
147-
ConnectTimeout time.Duration
148-
Dialer Dialer
149-
HostDialer HostDialer
150-
Compressor Compressor
151-
Authenticator Authenticator
152-
AuthProvider func(h *HostInfo) (Authenticator, error)
153-
Keepalive time.Duration
154-
Logger StdLogger
155-
143+
Dialer Dialer
144+
Logger StdLogger
145+
Authenticator Authenticator
146+
Compressor Compressor
147+
HostDialer HostDialer
148+
AuthProvider func(h *HostInfo) (Authenticator, error)
156149
tlsConfig *tls.Config
150+
CQLVersion string
151+
ConnectTimeout time.Duration
152+
ReadTimeout time.Duration
153+
WriteTimeout time.Duration
154+
ProtoVersion int
155+
Keepalive time.Duration
157156
disableCoalesce bool
158157
}
159158

@@ -189,52 +188,43 @@ type ConnInterface interface {
189188
// queries, but users are usually advised to use a more reliable, higher
190189
// level API.
191190
type Conn struct {
192-
conn net.Conn
193-
r *bufio.Reader
194-
w contextWriter
195-
196-
systemRequestTimeout time.Duration
197-
usingTimeoutClause string
198-
readTimeout atomic.Int64
199-
writeTimeout atomic.Int64
200-
cfg *ConnConfig
201-
frameObserver FrameHeaderObserver
202-
streamObserver StreamObserver
203-
204-
headerBuf [headSize]byte
205-
206-
streams *streams.IDGenerator
207-
mu sync.Mutex
191+
auth Authenticator
192+
streamObserver StreamObserver
193+
w contextWriter
194+
logger StdLogger
195+
frameObserver FrameHeaderObserver
196+
ctx context.Context
197+
errorHandler ConnErrorHandler
198+
compressor Compressor
199+
conn net.Conn
200+
cfg *ConnConfig
201+
supported map[string][]string
202+
streams *streams.IDGenerator
203+
host *HostInfo
208204
// calls stores a map from stream ID to callReq.
209205
// This map is protected by mu.
210206
// calls should not be used when closed is true, calls is set to nil when closed=true.
211-
calls map[int]*callReq
212-
213-
errorHandler ConnErrorHandler
214-
compressor Compressor
215-
auth Authenticator
216-
addr string
217-
218-
version uint8
219-
currentKeyspace string
220-
host *HostInfo
221-
supported map[string][]string
222-
scyllaSupported scyllaSupported
223-
cqlProtoExts []cqlProtocolExtension
224-
isSchemaV2 bool
225-
226-
session *Session
227-
207+
calls map[int]*callReq
208+
r *bufio.Reader
209+
session *Session
210+
cancel context.CancelFunc
211+
addr string
212+
usingTimeoutClause string
213+
currentKeyspace string
214+
cqlProtoExts []cqlProtocolExtension
215+
scyllaSupported scyllaSupported
216+
systemRequestTimeout time.Duration
217+
writeTimeout atomic.Int64
218+
timeouts int64
219+
readTimeout atomic.Int64
220+
mu sync.Mutex
221+
tabletsRoutingV1 int32
222+
headerBuf [headSize]byte
228223
// true if connection close process for the connection started.
229224
// closed is protected by mu.
230-
closed bool
231-
ctx context.Context
232-
cancel context.CancelFunc
233-
234-
timeouts int64
235-
236-
logger StdLogger
237-
tabletsRoutingV1 int32
225+
closed bool
226+
isSchemaV2 bool
227+
version uint8
238228
}
239229

240230
func (c *Conn) getIsSchemaV2() bool {
@@ -887,16 +877,13 @@ func (c *Conn) releaseStream(call *callReq) {
887877
}
888878

889879
type callReq struct {
880+
// streamObserverContext is notified about events regarding this stream
881+
streamObserverContext StreamObserverContext
890882
// resp will receive the frame that was sent as a response to this stream.
891883
resp chan callResp
892884
timeout chan struct{} // indicates to recv() that a call has timed out
893-
streamID int // current stream in use
894-
895-
timer *time.Timer
896-
897-
// streamObserverContext is notified about events regarding this stream
898-
streamObserverContext StreamObserverContext
899-
885+
timer *time.Timer
886+
streamID int // current stream in use
900887
// streamObserverEndOnce ensures that either StreamAbandoned or StreamFinished is called,
901888
// but not both.
902889
streamObserverEndOnce sync.Once
@@ -932,14 +919,13 @@ type deadlineWriter interface {
932919
}
933920

934921
type deadlineContextWriter struct {
935-
w deadlineWriter
936-
timeout atomic.Int64
922+
w deadlineWriter
937923
// semaphore protects critical section for SetWriteDeadline/Write.
938924
// It is a channel with capacity 1.
939925
semaphore chan struct{}
940-
941926
// quit closed once the connection is closed.
942-
quit chan struct{}
927+
quit chan struct{}
928+
timeout atomic.Int64
943929
}
944930

945931
func (c *deadlineContextWriter) setWriteTimeout(timeout time.Duration) {
@@ -985,17 +971,13 @@ func newWriteCoalescer(conn deadlineWriter, writeTimeout, coalesceDuration time.
985971
}
986972

987973
type writeCoalescer struct {
988-
c deadlineWriter
989-
990-
mu sync.Mutex
991-
992-
quit <-chan struct{}
993-
writeCh chan writeRequest
994-
995-
timeout atomic.Int64
996-
974+
c deadlineWriter
975+
quit <-chan struct{}
976+
writeCh chan writeRequest
997977
testEnqueuedHook func()
998978
testFlushedHook func()
979+
timeout atomic.Int64
980+
mu sync.Mutex
999981
}
1000982

1001983
func (w *writeCoalescer) setWriteTimeout(timeout time.Duration) {
@@ -1010,8 +992,8 @@ type writeRequest struct {
1010992
}
1011993

1012994
type writeResult struct {
1013-
n int
1014995
err error
996+
n int
1015997
}
1016998

1017999
// writeContext implements contextWriter.
@@ -1345,8 +1327,8 @@ type StreamObserverContext interface {
13451327

13461328
type preparedStatment struct {
13471329
id []byte
1348-
request preparedMetadata
13491330
response resultMetadata
1331+
request preparedMetadata
13501332
}
13511333

13521334
type inflightPrepare struct {
@@ -1869,9 +1851,9 @@ func getSchemaAgreement(queryLocalSchemasRows []string, querySystemPeersRows []s
18691851
type schemaAgreementHost struct {
18701852
DataCenter string
18711853
Rack string
1854+
RPCAddress string
18721855
HostID UUID
18731856
SchemaVersion UUID
1874-
RPCAddress string
18751857
}
18761858

18771859
func (h *schemaAgreementHost) IsValid() bool {

connectionpool.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,12 @@ type SetTablets interface {
5252
}
5353

5454
type policyConnPool struct {
55-
session *Session
56-
57-
port int
58-
numConns int
59-
keyspace string
60-
61-
mu sync.RWMutex
55+
session *Session
6256
hostConnPools map[string]*hostConnPool
57+
keyspace string
58+
port int
59+
numConns int
60+
mu sync.RWMutex
6361
}
6462

6563
func connConfig(cfg *ClusterConfig) (*ConnConfig, error) {
@@ -253,18 +251,17 @@ func (p *policyConnPool) removeHost(hostID string) {
253251
// hostConnPool is a connection pool for a single host.
254252
// Connection selection is based on a provided ConnSelectionPolicy
255253
type hostConnPool struct {
256-
session *Session
257-
host *HostInfo
258-
size int
259-
keyspace string
260-
// protection for connPicker, closed, filling
261-
mu sync.RWMutex
262254
connPicker ConnPicker
263-
closed bool
264-
filling bool
255+
logger StdLogger
256+
session *Session
257+
host *HostInfo
265258
debouncer *debounce.SimpleDebouncer
266-
267-
logger StdLogger
259+
keyspace string
260+
size int
261+
// protection for connPicker, closed, filling
262+
mu sync.RWMutex
263+
closed bool
264+
filling bool
268265
}
269266

270267
func (h *hostConnPool) String() string {

control.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,12 @@ type controlConnection interface {
7373
// Ensure that the atomic variable is aligned to a 64bit boundary
7474
// so that atomic operations can be applied on 32bit architectures.
7575
type controlConn struct {
76+
conn atomic.Value
77+
retry RetryPolicy
78+
session *Session
79+
quit chan struct{}
7680
state int32
7781
reconnecting int32
78-
79-
session *Session
80-
conn atomic.Value
81-
82-
retry RetryPolicy
83-
84-
quit chan struct{}
8582
}
8683

8784
func (c *controlConn) getSession() *Session {

debounce/refresh_deboucer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ const (
1111

1212
// debounces requests to call a refresh function (currently used for ring refresh). It also supports triggering a refresh immediately.
1313
type RefreshDebouncer struct {
14-
mu sync.Mutex
15-
stopped bool
1614
broadcaster *errorBroadcaster
17-
interval time.Duration
1815
timer *time.Timer
1916
refreshNowCh chan struct{}
2017
quit chan struct{}
2118
refreshFn func() error
19+
interval time.Duration
20+
mu sync.Mutex
21+
stopped bool
2222
}
2323

2424
func NewRefreshDebouncer(interval time.Duration, refreshFn func() error) *RefreshDebouncer {

dialer/recorder/recorder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ func NewConnectionRecorder(fname string, conn net.Conn) (net.Conn, error) {
5757
}
5858

5959
type FrameWriter struct {
60-
new bool
61-
to_record int
6260
record dialer.Record
61+
to_record int
62+
new bool
6363
}
6464

6565
func (f *FrameWriter) Write(b []byte, n int, file *os.File) (err error) {

dialer/replayer/replayer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ func NewConnectionReplayer(fname string) (net.Conn, error) {
4040
}
4141

4242
type ConnectionReplayer struct {
43+
gotRequest chan struct{}
4344
frames []*FrameRecorded
4445
frameIdsToReplay []int
4546
streamIdsToReplay []int
4647
frameIdx int
4748
frameResponsePosition int
48-
gotRequest chan struct{}
4949
closed bool
5050
}
5151

@@ -220,6 +220,6 @@ func loadResponseFramesFromFiles(read_file, write_file string) ([]*FrameRecorded
220220
}
221221

222222
type FrameRecorded struct {
223-
Hash int64
224223
Response []byte
224+
Hash int64
225225
}

0 commit comments

Comments
 (0)