github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/closedts/ctpb/entry.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package ctpb 12 13 import ( 14 "fmt" 15 "sort" 16 "strings" 17 18 "github.com/cockroachdb/cockroach/pkg/roachpb" 19 ) 20 21 // Epoch is an int64 with its own type to avoid mix-ups in positional arguments. 22 type Epoch int64 23 24 // LAI is an int64 denoting a lease applied index with its own type to avoid 25 // mix-ups in positional arguments. 26 type LAI int64 27 28 // String formats Entry for human consumption as well as testing (by avoiding 29 // randomness in the output caused by map iteraton order). 30 func (e Entry) String() string { 31 rangeIDs := make([]roachpb.RangeID, 0, len(e.MLAI)) 32 for k := range e.MLAI { 33 rangeIDs = append(rangeIDs, k) 34 } 35 36 sort.Slice(rangeIDs, func(i, j int) bool { 37 a, b := rangeIDs[i], rangeIDs[j] 38 if a == b { 39 return e.MLAI[a] < e.MLAI[b] 40 } 41 return a < b 42 }) 43 sl := make([]string, 0, len(rangeIDs)) 44 for _, rangeID := range rangeIDs { 45 sl = append(sl, fmt.Sprintf("r%d: %d", rangeID, e.MLAI[rangeID])) 46 } 47 if len(sl) == 0 { 48 sl = []string{"(empty)"} 49 } 50 return fmt.Sprintf("CT: %s @ Epoch %d\nFull: %t\nMLAI: %s\n", e.ClosedTimestamp, e.Epoch, e.Full, strings.Join(sl, ", ")) 51 } 52 53 func (r Reaction) String() string { 54 return fmt.Sprintf("Refresh: %v", r.Requested) 55 }