util

package
v1.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2018 License: Apache-2.0 Imports: 17 Imported by: 2,949

Documentation

Overview

Package util is a generated protocol buffer package.

It is generated from these files:

cockroach/pkg/util/unresolved_addr.proto

It has these top-level messages:

UnresolvedAddr

Index

Constants

View Source
const RaceEnabled = false

RaceEnabled is true if CockroachDB was built with the race build tag.

Variables

View Source
var (
	ErrInvalidLengthUnresolvedAddr = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowUnresolvedAddr   = fmt.Errorf("proto: integer overflow")
)
View Source
var TestAddr = NewUnresolvedAddr("tcp", "127.0.0.1:0")

TestAddr is an address to use for test servers. Listening on port 0 causes the kernel to allocate an unused port.

Functions

func CRC32 added in v1.1.0

func CRC32(data []byte) uint32

CRC32 computes the Castagnoli CRC32 of the given data.

func EqualPtrFields

func EqualPtrFields(src, dst reflect.Value, prefix string) []string

EqualPtrFields uses reflection to check two "mirror" structures for matching pointer fields that point to the same object. Used to verify cloning/deep copy functions.

Returns the names of equal pointer fields.

func GetSingleRune added in v1.1.0

func GetSingleRune(s string) (rune, error)

GetSingleRune decodes the string s as a single rune if possible.

func GetSmallTrace

func GetSmallTrace(skip int) string

GetSmallTrace produces a ":"-separated single line containing the topmost 5 callers from a given skip level.

func MoveTopKToFront

func MoveTopKToFront(data sort.Interface, k int)

MoveTopKToFront moves the top K elements to the front. It makes O(n) calls to data.Less and data.Swap (with very high probability). It uses Hoare's selection algorithm (aka quickselect).

func Pluralize

func Pluralize(n int64) string

Pluralize returns a single character 's' unless n == 1.

func RetryForDuration

func RetryForDuration(duration time.Duration, fn func() error) error

RetryForDuration will retry the given function until it either returns without error, or the given duration has elapsed. The function is invoked immediately at first and then successively with an exponential backoff starting at 1ns and ending at the specified duration.

func RoundUpPowerOfTwo

func RoundUpPowerOfTwo(x int64) int64

RoundUpPowerOfTwo returns the first power of 2 greater or equal to the number. Source: http://graphics.stanford.edu/%7Eseander/bithacks.html#RoundUpPowerOf2

func TruncateDuration

func TruncateDuration(d time.Duration, r time.Duration) time.Duration

TruncateDuration returns a new duration obtained from the first argument by discarding the portions at finer resolution than that given by the second argument. Example: TruncateDuration(time.Second+1, time.Second) == time.Second.

func UnexpectedWithIssueErrorf added in v1.1.0

func UnexpectedWithIssueErrorf(issue int, format string, args ...interface{}) error

UnexpectedWithIssueErrorf constructs an UnexpectedWithIssueError with the provided issue and formatted message.

Types

type FastIntSet added in v1.1.0

type FastIntSet struct {
	// contains filtered or unexported fields
}

FastIntSet keeps track of a set of integers. It does not perform any allocations when the values are small. It is not thread-safe.

func MakeFastIntSet added in v1.1.0

func MakeFastIntSet(elements ...uint32) FastIntSet

MakeFastIntSet initializes a FastIntSet with the given elements.

func (*FastIntSet) Add added in v1.1.0

func (s *FastIntSet) Add(i uint32)

Add adds a value to the set. No-op if the value is already in the set.

func (*FastIntSet) Contains added in v1.1.0

func (s *FastIntSet) Contains(i uint32) bool

Contains returns true if the set contains the value.

func (*FastIntSet) Copy added in v1.1.0

func (s *FastIntSet) Copy() FastIntSet

Copy makes an copy of a FastIntSet which can be modified independently.

func (*FastIntSet) Empty added in v1.1.0

func (s *FastIntSet) Empty() bool

Empty returns true if the set is empty.

func (*FastIntSet) Equals added in v1.1.0

func (s *FastIntSet) Equals(rhs FastIntSet) bool

Equals returns true if the two sets are identical.

func (*FastIntSet) ForEach added in v1.1.0

func (s *FastIntSet) ForEach(f func(i uint32))

ForEach calls a function for each value in the set (in arbitrary order).

func (*FastIntSet) Next added in v1.1.0

func (s *FastIntSet) Next(startVal uint32) (uint32, bool)

Next returns the first value in the set which is >= startVal. If there is no value, the second return value is false. Note: this is efficient for small sets, but each call takes linear time for large sets.

func (*FastIntSet) Ordered added in v1.1.0

func (s *FastIntSet) Ordered() []int

Ordered returns a slice with all the integers in the set, in sorted order.

func (*FastIntSet) Remove added in v1.1.0

func (s *FastIntSet) Remove(i uint32)

Remove removes a value from the set. No-op if the value is not in the set.

func (*FastIntSet) String added in v1.1.0

func (s *FastIntSet) String() string

type NoCopy

type NoCopy struct{}

NoCopy may be embedded into structs which must not be copied after the first use.

See https://github.com/golang/go/issues/8005#issuecomment-190753527 for details.

func (*NoCopy) Lock

func (*NoCopy) Lock()

Lock is a no-op used by -copylocks checker from `go vet`.

type UnexpectedWithIssueErr added in v1.1.0

type UnexpectedWithIssueErr struct {
	// contains filtered or unexported fields
}

UnexpectedWithIssueErr indicates an error with an associated Github issue. It's supposed to be used for conditions that would otherwise be checked by assertions, except that they fail and we need the public's help for tracking it down. The error message will invite users to report repros.

Modeled after pgerror.Unimplemented.

func (UnexpectedWithIssueErr) Error added in v1.1.0

func (e UnexpectedWithIssueErr) Error() string

Error implements the error interface.

type UnresolvedAddr

type UnresolvedAddr struct {
	NetworkField string `protobuf:"bytes,1,opt,name=network_field,json=networkField" json:"network_field"`
	AddressField string `protobuf:"bytes,2,opt,name=address_field,json=addressField" json:"address_field"`
}

/ UnresolvedAddr is an unresolved version of net.Addr.

var IsolatedTestAddr *UnresolvedAddr

IsolatedTestAddr is an address to use for tests that need extra isolation by using more addresses than 127.0.0.1 (support for this is platform-specific and only enabled on Linux). Both TestAddr and IsolatedTestAddr guarantee that the chosen port is not in use when allocated, but IsolatedTestAddr draws from a larger pool of addresses so that when tests are run in a tight loop the system is less likely to run out of available ports or give a port to one test immediately after it was closed by another.

IsolatedTestAddr should be used for tests that open and close a large number of sockets, or tests which stop a server and rely on seeing a "connection refused" error afterwards. It cannot be used with tests that operate in secure mode since our test certificates are only valid for 127.0.0.1.

func MakeUnresolvedAddr

func MakeUnresolvedAddr(network, addr string) UnresolvedAddr

MakeUnresolvedAddr populates an UnresolvedAddr from a network and raw address string.

func NewUnresolvedAddr

func NewUnresolvedAddr(network, addr string) *UnresolvedAddr

NewUnresolvedAddr creates a new UnresolvedAddr from a network and raw address string.

func (*UnresolvedAddr) Descriptor

func (*UnresolvedAddr) Descriptor() ([]byte, []int)

func (UnresolvedAddr) IsEmpty

func (a UnresolvedAddr) IsEmpty() bool

IsEmpty returns true if the address has no network or address specified.

func (*UnresolvedAddr) Marshal

func (m *UnresolvedAddr) Marshal() (dAtA []byte, err error)

func (*UnresolvedAddr) MarshalTo

func (m *UnresolvedAddr) MarshalTo(dAtA []byte) (int, error)

func (*UnresolvedAddr) Network

func (a *UnresolvedAddr) Network() string

Network returns the address's network name.

func (*UnresolvedAddr) ProtoMessage

func (*UnresolvedAddr) ProtoMessage()

func (*UnresolvedAddr) Reset

func (m *UnresolvedAddr) Reset()

func (UnresolvedAddr) Resolve

func (a UnresolvedAddr) Resolve() (net.Addr, error)

Resolve attempts to resolve a into a net.Addr.

func (*UnresolvedAddr) Size

func (m *UnresolvedAddr) Size() (n int)

func (*UnresolvedAddr) String

func (a *UnresolvedAddr) String() string

String returns the address's string form.

func (*UnresolvedAddr) Unmarshal

func (m *UnresolvedAddr) Unmarshal(dAtA []byte) error

Directories

Path Synopsis
Package hlc implements the Hybrid Logical Clock outlined in "Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases", available online at http://www.cse.buffalo.edu/tech-reports/2014-04.pdf.
Package hlc implements the Hybrid Logical Clock outlined in "Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases", available online at http://www.cse.buffalo.edu/tech-reports/2014-04.pdf.
Package interval provides two implementations for an interval tree.
Package interval provides two implementations for an interval tree.
Package leaktest provides tools to detect leaked goroutines in tests.
Package leaktest provides tools to detect leaked goroutines in tests.
log
Package log implements logging analogous to the Google-internal C++ INFO/ERROR/V setup.
Package log implements logging analogous to the Google-internal C++ INFO/ERROR/V setup.
Package metric provides server metrics (a.k.a.
Package metric provides server metrics (a.k.a.
Package sdnotify implements both sides of the systemd readiness protocol.
Package sdnotify implements both sides of the systemd readiness protocol.
singleflight
Package singleflight provides a duplicate function call suppression mechanism.
Package singleflight provides a duplicate function call suppression mechanism.
Package tracing is a generated protocol buffer package.
Package tracing is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL