github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/go-hbase/utils.go (about) 1 package hbase 2 3 import ( 4 "bytes" 5 "time" 6 7 "github.com/insionng/yougam/libraries/juju/errors" 8 "github.com/insionng/yougam/libraries/pingcap/go-hbase/proto" 9 ) 10 11 func retrySleep(retries int) { 12 time.Sleep(time.Duration(retries*500) * time.Millisecond) 13 } 14 15 func findKey(region *RegionInfo, key []byte) bool { 16 if region == nil { 17 return false 18 } 19 // StartKey <= key < EndKey 20 return (len(region.StartKey) == 0 || bytes.Compare(region.StartKey, key) <= 0) && 21 (len(region.EndKey) == 0 || bytes.Compare(key, region.EndKey) < 0) 22 } 23 24 func NewRegionSpecifier(regionName string) *proto.RegionSpecifier { 25 return &proto.RegionSpecifier{ 26 Type: proto.RegionSpecifier_REGION_NAME.Enum(), 27 Value: []byte(regionName), 28 } 29 } 30 31 // TODO: The following functions can be moved later. 32 // ErrorEqual returns a boolean indicating whether err1 is equal to err2. 33 func ErrorEqual(err1, err2 error) bool { 34 e1 := errors.Cause(err1) 35 e2 := errors.Cause(err2) 36 37 if e1 == e2 { 38 return true 39 } 40 41 if e1 == nil || e2 == nil { 42 return e1 == e2 43 } 44 45 return e1.Error() == e2.Error() 46 } 47 48 // ErrorNotEqual returns a boolean indicating whether err1 isn't equal to err2. 49 func ErrorNotEqual(err1, err2 error) bool { 50 return !ErrorEqual(err1, err2) 51 }