Skip to content

Commit 020b55c

Browse files
authored
Chore: deprecated usages (#1329)
* chore: move from CAS to CompareAndSwap because deprecated * chore: since go1.20 initialize a random seed is deprecated
1 parent 4e71a47 commit 020b55c

File tree

8 files changed

+16
-22
lines changed

8 files changed

+16
-22
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ coverage.html
1414
perf/perf
1515
pulsar-perf
1616
bin
17+
18+
vendor/

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/spf13/cobra v1.6.1
2626
github.com/stretchr/testify v1.9.0
2727
github.com/testcontainers/testcontainers-go v0.32.0
28-
go.uber.org/atomic v1.7.0
28+
go.uber.org/atomic v1.11.0
2929
golang.org/x/mod v0.20.0
3030
golang.org/x/oauth2 v0.11.0
3131
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lI
407407
go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM=
408408
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
409409
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
410+
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
411+
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
410412
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
411413
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
412414
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=

pulsar/consumer_partition.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (p *availablePermits) flowIfNeed() {
257257
availablePermits := current
258258
requestedPermits := current
259259
// check if permits changed
260-
if !p.permits.CAS(current, 0) {
260+
if !p.permits.CompareAndSwap(current, 0) {
261261
return
262262
}
263263

@@ -2084,13 +2084,13 @@ func (pc *partitionConsumer) expectMoreIncomingMessages() {
20842084
if !pc.options.autoReceiverQueueSize {
20852085
return
20862086
}
2087-
if pc.scaleReceiverQueueHint.CAS(true, false) {
2087+
if pc.scaleReceiverQueueHint.CompareAndSwap(true, false) {
20882088
oldSize := pc.currentQueueSize.Load()
20892089
maxSize := int32(pc.options.receiverQueueSize)
20902090
newSize := int32(math.Min(float64(maxSize), float64(oldSize*2)))
20912091
usagePercent := pc.client.memLimit.CurrentUsagePercent()
20922092
if usagePercent < receiverQueueExpansionMemThreshold && newSize > oldSize {
2093-
pc.currentQueueSize.CAS(oldSize, newSize)
2093+
pc.currentQueueSize.CompareAndSwap(oldSize, newSize)
20942094
pc.availablePermits.add(newSize - oldSize)
20952095
pc.log.Debugf("update currentQueueSize from %d -> %d", oldSize, newSize)
20962096
}
@@ -2116,7 +2116,7 @@ func (pc *partitionConsumer) shrinkReceiverQueueSize() {
21162116
minSize := int32(math.Min(float64(initialReceiverQueueSize), float64(pc.options.receiverQueueSize)))
21172117
newSize := int32(math.Max(float64(minSize), float64(oldSize/2)))
21182118
if newSize < oldSize {
2119-
pc.currentQueueSize.CAS(oldSize, newSize)
2119+
pc.currentQueueSize.CompareAndSwap(oldSize, newSize)
21202120
pc.availablePermits.add(newSize - oldSize)
21212121
pc.log.Debugf("update currentQueueSize from %d -> %d", oldSize, newSize)
21222122
}

pulsar/message_chunking_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ func TestInvalidChunkingConfig(t *testing.T) {
5757
}
5858

5959
func TestLargeMessage(t *testing.T) {
60-
rand.Seed(time.Now().Unix())
61-
6260
client, err := NewClient(ClientOptions{
6361
URL: lookupURL,
6462
})
@@ -208,7 +206,6 @@ func TestMaxPendingChunkMessages(t *testing.T) {
208206
}
209207

210208
func TestExpireIncompleteChunks(t *testing.T) {
211-
rand.Seed(time.Now().Unix())
212209
client, err := NewClient(ClientOptions{
213210
URL: lookupURL,
214211
})
@@ -240,8 +237,6 @@ func TestExpireIncompleteChunks(t *testing.T) {
240237
}
241238

242239
func TestChunksEnqueueFailed(t *testing.T) {
243-
rand.Seed(time.Now().Unix())
244-
245240
client, err := NewClient(ClientOptions{
246241
URL: lookupURL,
247242
})
@@ -278,8 +273,6 @@ func TestChunksEnqueueFailed(t *testing.T) {
278273
}
279274

280275
func TestSeekChunkMessages(t *testing.T) {
281-
rand.Seed(time.Now().Unix())
282-
283276
client, err := NewClient(ClientOptions{
284277
URL: lookupURL,
285278
})
@@ -343,8 +336,6 @@ func TestSeekChunkMessages(t *testing.T) {
343336
}
344337

345338
func TestChunkAckAndNAck(t *testing.T) {
346-
rand.Seed(time.Now().Unix())
347-
348339
client, err := NewClient(ClientOptions{
349340
URL: lookupURL,
350341
})
@@ -400,8 +391,6 @@ func TestChunkAckAndNAck(t *testing.T) {
400391
}
401392

402393
func TestChunkSize(t *testing.T) {
403-
rand.Seed(time.Now().Unix())
404-
405394
client, err := NewClient(ClientOptions{
406395
URL: lookupURL,
407396
})

pulsar/producer_partition.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ func (p *partitionProducer) Send(ctx context.Context, msg *ProducerMessage) (Mes
10891089
doneCh := make(chan struct{})
10901090

10911091
p.internalSendAsync(ctx, msg, func(ID MessageID, _ *ProducerMessage, e error) {
1092-
if isDone.CAS(false, true) {
1092+
if isDone.CompareAndSwap(false, true) {
10931093
err = e
10941094
msgID = ID
10951095
close(doneCh)
@@ -1394,7 +1394,8 @@ func (p *partitionProducer) ReceivedSendReceipt(response *pb.CommandSendReceipt)
13941394
)
13951395

13961396
if sr.totalChunks > 1 {
1397-
if sr.chunkID == 0 {
1397+
switch sr.chunkID {
1398+
case 0:
13981399
sr.chunkRecorder.setFirstChunkID(
13991400
&messageID{
14001401
int64(response.MessageId.GetLedgerId()),
@@ -1403,7 +1404,7 @@ func (p *partitionProducer) ReceivedSendReceipt(response *pb.CommandSendReceipt)
14031404
p.partitionIdx,
14041405
0,
14051406
})
1406-
} else if sr.chunkID == sr.totalChunks-1 {
1407+
case sr.totalChunks - 1:
14071408
sr.chunkRecorder.setLastChunkID(
14081409
&messageID{
14091410
int64(response.MessageId.GetLedgerId()),
@@ -1546,7 +1547,7 @@ func (p *partitionProducer) setProducerState(state producerState) {
15461547
// set a new producerState and return the last state
15471548
// returns bool if the new state has been set or not
15481549
func (p *partitionProducer) casProducerState(oldState, newState producerState) bool {
1549-
return p.state.CAS(int32(oldState), int32(newState))
1550+
return p.state.CompareAndSwap(int32(oldState), int32(newState))
15501551
}
15511552

15521553
func (p *partitionProducer) Close() {

pulsar/producer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1977,8 +1977,8 @@ func TestWaitForExclusiveProducer(t *testing.T) {
19771977
Topic: topicName,
19781978
ProducerAccessMode: ProducerAccessModeWaitForExclusive,
19791979
})
1980-
defer producer2.Close()
19811980
assert.NoError(t, err)
1981+
defer producer2.Close()
19821982
assert.NotNil(t, producer2)
19831983

19841984
id, err := producer2.Send(context.Background(), &ProducerMessage{

pulsar/transaction_coordinator_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func (t *transactionHandler) endTxn(op *endTxnOp) {
319319
}
320320

321321
func (t *transactionHandler) close() {
322-
if !t.state.CAS(txnHandlerReady, txnHandlerClosed) {
322+
if !t.state.CompareAndSwap(txnHandlerReady, txnHandlerClosed) {
323323
return
324324
}
325325
close(t.closeCh)

0 commit comments

Comments
 (0)