Skip to content

Commit

Permalink
Remove unnecessary logs
Browse files Browse the repository at this point in the history
Signed-off-by: Bin Shi <binshi.bing@gmail.com>

Add debugging log

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

Add uuid

Signed-off-by: Bin Shi <binshi.bing@gmail.com>
  • Loading branch information
binshi-bing committed May 16, 2023
1 parent d11f127 commit 966fc15
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
26 changes: 19 additions & 7 deletions client/tso_service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package pd
import (
"context"
"fmt"
"reflect"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -68,7 +69,7 @@ func (k *keyspaceGroupSvcDiscovery) update(
keyspaceGroup *tsopb.KeyspaceGroup,
newPrimaryAddr string,
secondaryAddrs, addrs []string,
) (oldPrimaryAddr string, primarySwitched bool) {
) (oldPrimaryAddr string, primarySwitched, secondaryChanged bool) {
k.Lock()
defer k.Unlock()

Expand All @@ -79,10 +80,13 @@ func (k *keyspaceGroupSvcDiscovery) update(
k.primaryAddr = newPrimaryAddr
}

if !reflect.DeepEqual(k.secondaryAddrs, secondaryAddrs) {
k.secondaryAddrs = secondaryAddrs
secondaryChanged = true
}

k.group = keyspaceGroup
k.secondaryAddrs = secondaryAddrs
k.addrs = addrs

return
}

Expand Down Expand Up @@ -446,13 +450,11 @@ func (c *tsoServiceDiscovery) updateMember() error {
}
members[0].IsPrimary = true
keyspaceGroup = &tsopb.KeyspaceGroup{
Id: c.keyspaceID,
Id: defaultKeySpaceGroupID,
Members: members,
}
}

log.Info("[tso] update keyspace group", zap.String("keyspace-group", keyspaceGroup.String()))

// Initialize the serving addresses from the returned keyspace group info.
primaryAddr := ""
secondaryAddrs := make([]string, 0)
Expand All @@ -478,12 +480,16 @@ func (c *tsoServiceDiscovery) updateMember() error {
}
}

oldPrimary, primarySwitched := c.keyspaceGroupSD.update(keyspaceGroup, primaryAddr, secondaryAddrs, addrs)
oldPrimary, primarySwitched, secondaryChanged :=
c.keyspaceGroupSD.update(keyspaceGroup, primaryAddr, secondaryAddrs, addrs)
if primarySwitched {
if err := c.afterPrimarySwitched(oldPrimary, primaryAddr); err != nil {
return err
}
}
if primarySwitched || secondaryChanged {
log.Info("[tso] update tso server/pod list", zap.Strings("tso-servers", addrs))
}

// Even if the primary address is empty, we still updated other returned info above, including the
// keyspace group info and the secondary addresses.
Expand All @@ -502,6 +508,12 @@ func (c *tsoServiceDiscovery) findGroupByKeyspaceID(
failpoint.Inject("unexpectedCallOfFindGroupByKeyspaceID", func() {
panic("findGroupByKeyspaceID is called unexpectedly")
})
failpoint.Inject("unexpectedCallOfFindGroupByKeyspaceID", func(val failpoint.Value) {
keyspaceToCheck, ok := val.(int)
if ok && keyspaceID == uint32(keyspaceToCheck) {
panic("findGroupByKeyspaceID is called unexpectedly")
}
})
ctx, cancel := context.WithTimeout(c.ctx, timeout)
defer cancel()

Expand Down
36 changes: 18 additions & 18 deletions tests/integrations/tso/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package tso

import (
"context"
"fmt"
"math"
"math/rand"
"strings"
Expand All @@ -30,6 +31,7 @@ import (
"github.com/tikv/pd/client/testutil"
bs "github.com/tikv/pd/pkg/basicserver"
mcsutils "github.com/tikv/pd/pkg/mcs/utils"
"github.com/tikv/pd/pkg/slice"
"github.com/tikv/pd/pkg/storage/endpoint"
"github.com/tikv/pd/pkg/utils/tempurl"
"github.com/tikv/pd/pkg/utils/tsoutil"
Expand Down Expand Up @@ -227,33 +229,31 @@ func (suite *tsoClientTestSuite) TestGetTSAsync() {

func (suite *tsoClientTestSuite) TestDiscoverTSOServiceWithLegacyPath() {
re := suite.Require()
// Make sure this keyspace ID isn't used anywhere.
keyspaceID := uint32(1000000)
re.False(slice.Contains(suite.keyspaceIDs, keyspaceID))
failpointReturnString := fmt.Sprintf(`return("%d")`, keyspaceID)
// Simulate the case that the server has lower version than the client and returns no tso addrs
// in the GetClusterInfo RPC.
re.NoError(failpoint.Enable("github.com/tikv/pd/client/serverReturnsNoTSOAddrs", `return(true)`))
re.NoError(failpoint.Enable("github.com/tikv/pd/client/serverReturnsNoTSOAddrs", failpointReturnString))
re.NoError(failpoint.Enable("github.com/tikv/pd/client/unexpectedCallOfFindGroupByKeyspaceID", `return(true)`))
defer func() {
re.NoError(failpoint.Disable("github.com/tikv/pd/client/serverReturnsNoTSOAddrs"))
re.NoError(failpoint.Disable("github.com/tikv/pd/client/unexpectedCallOfFindGroupByKeyspaceID"))
}()

var wg sync.WaitGroup
wg.Add(tsoRequestConcurrencyNumber)
for i := 0; i < tsoRequestConcurrencyNumber; i++ {
go func() {
defer wg.Done()
client := mcs.SetupClientWithDefaultKeyspaceName(
suite.ctx, re, strings.Split(suite.backendEndpoints, ","))
var lastTS uint64
for j := 0; j < tsoRequestRound; j++ {
physical, logical, err := client.GetTS(suite.ctx)
suite.NoError(err)
ts := tsoutil.ComposeTS(physical, logical)
suite.Less(lastTS, ts)
lastTS = ts
}
}()
ctx, cancel := context.WithCancel(suite.ctx)
defer cancel()
client := mcs.SetupClientWithKeyspaceID(
ctx, re, keyspaceID, strings.Split(suite.backendEndpoints, ","))
var lastTS uint64
for j := 0; j < tsoRequestRound; j++ {
physical, logical, err := client.GetTS(ctx)
suite.NoError(err)
ts := tsoutil.ComposeTS(physical, logical)
suite.Less(lastTS, ts)
lastTS = ts
}
wg.Wait()
}

// TestGetMinTS tests the correctness of GetMinTS.
Expand Down

0 comments on commit 966fc15

Please sign in to comment.