mirror of https://github.com/tikv/client-go.git
Drop Go 1.17 support (#562)
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
This commit is contained in:
parent
516cfcdecc
commit
a31f03ebc4
|
|
@ -15,7 +15,7 @@ jobs:
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16
|
go-version: 1.18
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: go test ./...
|
run: go test ./...
|
||||||
|
|
@ -28,7 +28,7 @@ jobs:
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16
|
go-version: 1.18
|
||||||
|
|
||||||
- name: Test with race
|
- name: Test with race
|
||||||
run: go test -race ./...
|
run: go test -race ./...
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,6 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//go:build !go1.18
|
|
||||||
// +build !go1.18
|
|
||||||
|
|
||||||
package locate
|
package locate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -43,31 +40,31 @@ import (
|
||||||
"github.com/google/btree"
|
"github.com/google/btree"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SortedRegionsRegions is a sorted btree.
|
// SortedRegions is a sorted btree.
|
||||||
type SortedRegions struct {
|
type SortedRegions struct {
|
||||||
b *btree.BTree
|
b *btree.BTreeG[*btreeItem]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSortedRegions returns a new SortedRegions.
|
// NewSortedRegions returns a new SortedRegions.
|
||||||
func NewSortedRegions(btreeDegree int) *SortedRegions {
|
func NewSortedRegions(btreeDegree int) *SortedRegions {
|
||||||
return &SortedRegions{
|
return &SortedRegions{
|
||||||
b: btree.New(btreeDegree),
|
b: btree.NewG(btreeDegree, func(a, b *btreeItem) bool { return a.Less(b) }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplaceOrInsert inserts a new item into the btree.
|
// ReplaceOrInsert inserts a new item into the btree.
|
||||||
func (s *SortedRegions) ReplaceOrInsert(cachedRegion *Region) *Region {
|
func (s *SortedRegions) ReplaceOrInsert(cachedRegion *Region) *Region {
|
||||||
old := s.b.ReplaceOrInsert(newBtreeItem(cachedRegion))
|
old, _ := s.b.ReplaceOrInsert(newBtreeItem(cachedRegion))
|
||||||
if old != nil {
|
if old != nil {
|
||||||
return old.(*btreeItem).cachedRegion
|
return old.cachedRegion
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DescendLessOrEqual returns all items that are less than or equal to the key.
|
// DescendLessOrEqual returns all items that are less than or equal to the key.
|
||||||
func (s *SortedRegions) DescendLessOrEqual(key []byte, isEndKey bool, ts int64) (r *Region) {
|
func (s *SortedRegions) DescendLessOrEqual(key []byte, isEndKey bool, ts int64) (r *Region) {
|
||||||
s.b.DescendLessOrEqual(newBtreeSearchItem(key), func(item btree.Item) bool {
|
s.b.DescendLessOrEqual(newBtreeSearchItem(key), func(item *btreeItem) bool {
|
||||||
r = item.(*btreeItem).cachedRegion
|
r = item.cachedRegion
|
||||||
if isEndKey && bytes.Equal(r.StartKey(), key) {
|
if isEndKey && bytes.Equal(r.StartKey(), key) {
|
||||||
r = nil // clear result
|
r = nil // clear result
|
||||||
return true // iterate next item
|
return true // iterate next item
|
||||||
|
|
@ -83,8 +80,8 @@ func (s *SortedRegions) DescendLessOrEqual(key []byte, isEndKey bool, ts int64)
|
||||||
|
|
||||||
// AscendGreaterOrEqual returns all items that are greater than or equal to the key.
|
// AscendGreaterOrEqual returns all items that are greater than or equal to the key.
|
||||||
func (s *SortedRegions) AscendGreaterOrEqual(startKey, endKey []byte, limit int) (regions []*Region) {
|
func (s *SortedRegions) AscendGreaterOrEqual(startKey, endKey []byte, limit int) (regions []*Region) {
|
||||||
s.b.AscendGreaterOrEqual(newBtreeSearchItem(startKey), func(item btree.Item) bool {
|
s.b.AscendGreaterOrEqual(newBtreeSearchItem(startKey), func(item *btreeItem) bool {
|
||||||
region := item.(*btreeItem).cachedRegion
|
region := item.cachedRegion
|
||||||
if len(endKey) > 0 && bytes.Compare(region.StartKey(), endKey) >= 0 {
|
if len(endKey) > 0 && bytes.Compare(region.StartKey(), endKey) >= 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -101,8 +98,8 @@ func (s *SortedRegions) Clear() {
|
||||||
|
|
||||||
// ValidRegionsInBtree returns the number of valid regions in the btree.
|
// ValidRegionsInBtree returns the number of valid regions in the btree.
|
||||||
func (s *SortedRegions) ValidRegionsInBtree(ts int64) (len int) {
|
func (s *SortedRegions) ValidRegionsInBtree(ts int64) (len int) {
|
||||||
s.b.Descend(func(item btree.Item) bool {
|
s.b.Descend(func(item *btreeItem) bool {
|
||||||
r := item.(*btreeItem).cachedRegion
|
r := item.cachedRegion
|
||||||
if !r.checkRegionCacheTTL(ts) {
|
if !r.checkRegionCacheTTL(ts) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,113 +0,0 @@
|
||||||
// Copyright 2022 TiKV Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// NOTE: The code in this file is based on code from the
|
|
||||||
// TiDB project, licensed under the Apache License v 2.0
|
|
||||||
//
|
|
||||||
// https://github.com/pingcap/tidb/tree/cc5e161ac06827589c4966674597c137cc9e809c/store/tikv/locate/region_request.go
|
|
||||||
//
|
|
||||||
|
|
||||||
// Copyright 2016 PingCAP, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
//go:build go1.18
|
|
||||||
// +build go1.18
|
|
||||||
|
|
||||||
package locate
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
|
|
||||||
"github.com/google/btree"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SortedRegions is a sorted btree.
|
|
||||||
type SortedRegions struct {
|
|
||||||
b *btree.BTreeG[*btreeItem]
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewSortedRegions returns a new SortedRegions.
|
|
||||||
func NewSortedRegions(btreeDegree int) *SortedRegions {
|
|
||||||
return &SortedRegions{
|
|
||||||
b: btree.NewG(btreeDegree, func(a, b *btreeItem) bool { return a.Less(b) }),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReplaceOrInsert inserts a new item into the btree.
|
|
||||||
func (s *SortedRegions) ReplaceOrInsert(cachedRegion *Region) *Region {
|
|
||||||
old, _ := s.b.ReplaceOrInsert(newBtreeItem(cachedRegion))
|
|
||||||
if old != nil {
|
|
||||||
return old.cachedRegion
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DescendLessOrEqual returns all items that are less than or equal to the key.
|
|
||||||
func (s *SortedRegions) DescendLessOrEqual(key []byte, isEndKey bool, ts int64) (r *Region) {
|
|
||||||
s.b.DescendLessOrEqual(newBtreeSearchItem(key), func(item *btreeItem) bool {
|
|
||||||
r = item.cachedRegion
|
|
||||||
if isEndKey && bytes.Equal(r.StartKey(), key) {
|
|
||||||
r = nil // clear result
|
|
||||||
return true // iterate next item
|
|
||||||
}
|
|
||||||
if !r.checkRegionCacheTTL(ts) {
|
|
||||||
r = nil
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// AscendGreaterOrEqual returns all items that are greater than or equal to the key.
|
|
||||||
func (s *SortedRegions) AscendGreaterOrEqual(startKey, endKey []byte, limit int) (regions []*Region) {
|
|
||||||
s.b.AscendGreaterOrEqual(newBtreeSearchItem(startKey), func(item *btreeItem) bool {
|
|
||||||
region := item.cachedRegion
|
|
||||||
if len(endKey) > 0 && bytes.Compare(region.StartKey(), endKey) >= 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
regions = append(regions, region)
|
|
||||||
return len(regions) < limit
|
|
||||||
})
|
|
||||||
return regions
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear removes all items from the btree.
|
|
||||||
func (s *SortedRegions) Clear() {
|
|
||||||
s.b.Clear(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidRegionsInBtree returns the number of valid regions in the btree.
|
|
||||||
func (s *SortedRegions) ValidRegionsInBtree(ts int64) (len int) {
|
|
||||||
s.b.Descend(func(item *btreeItem) bool {
|
|
||||||
r := item.cachedRegion
|
|
||||||
if !r.checkRegionCacheTTL(ts) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
len++
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue