Documentation ¶
Overview ¶
- Copyright (C) 2017 Dgraph Labs, Inc. and Contributors *
- 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.
Package x contains some very common utilities used by Dgraph. These utilities are of "miscellaneous" nature, e.g., error checking.
Copyright (C) 2017 Dgraph Labs, Inc. and Contributors *
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 *
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.
Copyright (C) 2017 Dgraph Labs, Inc. and Contributors *
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 *
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.
Index ¶
- Constants
- Variables
- func AddCorsHeaders(w http.ResponseWriter)
- func AddInit(f func())
- func AppendProtoMsg(p []byte, msg ProtoMessage) ([]byte, error)
- func AppendUvarint(p []byte, x uint64) []byte
- func AssertTrue(b bool)
- func AssertTruef(b bool, format string, args ...interface{})
- func AssertTruefNoTrace(b bool, format string, args ...interface{})
- func BuildDetails() string
- func Check(err error)
- func Check2(_ interface{}, err error)
- func Checkf(err error, format string, args ...interface{})
- func CountKey(attr string, count uint32, reverse bool) []byte
- func DataKey(attr string, uid uint64) []byte
- func Errorf(format string, args ...interface{}) error
- func Fatalf(format string, args ...interface{})
- func GenerateTLSConfig(config TLSHelperConfig) (tlsCfg *tls.Config, reloadConfig func(), err error)
- func HealthCheck() error
- func IndexKey(attr, term string) []byte
- func Init(debug bool)
- func IsTestRun() bool
- func LoadTLSConfig(conf *TLSHelperConfig, v *viper.Viper)
- func NewTrace(title string, ctx context.Context) (trace.Trace, context.Context)
- func PageRange(count, offset, n int) (int, int)
- func ParseRequest(w http.ResponseWriter, r *http.Request, data interface{}) bool
- func PredicatePrefix(predicate string) []byte
- func PrintVersionOnly()
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func ReadLine(r *bufio.Reader, buf *bytes.Buffer) error
- func RegisterTLSFlags(flag *pflag.FlagSet)
- func RemoveDuplicates(s []string) (out []string)
- func Reply(w http.ResponseWriter, rep interface{})
- func ReserveCap(p []byte, atLeast int) []byte
- func ReverseKey(attr string, uid uint64) []byte
- func Round(d time.Duration) time.Duration
- func SchemaKey(attr string) []byte
- func SchemaPrefix() []byte
- func SetError(prev *error, n error)
- func SetStatus(w http.ResponseWriter, code, msg string)
- func SetStatusWithData(w http.ResponseWriter, code, msg string)
- func SetTestRun()
- func StartProfile(conf *viper.Viper) stopper
- func UpdateHealthStatus(ok bool)
- func UpdateMemoryStatus(ok bool)
- func ValidateAddress(addr string) bool
- func Version() string
- func Wrap(err error) error
- func Wrapf(err error, format string, args ...interface{}) error
- func WriteFileSync(filename string, data []byte, perm os.FileMode) error
- type BytesBuffer
- type Histogram
- type Options
- type ParsedKey
- func (p ParsedKey) CountPrefix(reverse bool) []byte
- func (p ParsedKey) DataPrefix() []byte
- func (p ParsedKey) IndexPrefix() []byte
- func (p ParsedKey) IsCount() bool
- func (p ParsedKey) IsData() bool
- func (p ParsedKey) IsIndex() bool
- func (p ParsedKey) IsReverse() bool
- func (p ParsedKey) IsSchema() bool
- func (p ParsedKey) IsType(typ byte) bool
- func (p ParsedKey) ReversePrefix() []byte
- func (p ParsedKey) SkipPredicate() []byte
- func (p ParsedKey) SkipRangeOfSameType() []byte
- func (p ParsedKey) SkipSchema() []byte
- type ProtoMessage
- type QueryResWithData
- type RaftValue
- type SafeMutex
- type SafeWait
- type SubCommand
- type TLSHelperConfig
- type Throttle
- type ValueTypeInfo
- type WaterMark
- func (w *WaterMark) Begin(index uint64)
- func (w *WaterMark) BeginMany(indices []uint64)
- func (w *WaterMark) Done(index uint64)
- func (w *WaterMark) DoneMany(indices []uint64)
- func (w *WaterMark) DoneUntil() uint64
- func (w *WaterMark) Init()
- func (w *WaterMark) SetDoneUntil(val uint64)
- func (w *WaterMark) WaitForMark(ctx context.Context, index uint64) error
Constants ¶
const ( // TODO(pawan) - Make this 2 bytes long. Right now ParsedKey has byteType and // bytePrefix. Change it so that it just has one field which has all the information. ByteData = byte(0x00) ByteIndex = byte(0x02) ByteReverse = byte(0x04) ByteCount = byte(0x08) ByteCountRev = ByteCount | ByteReverse )
const ( TLSClientConfig tlsConfigType = iota TLSServerConfig )
const ( Success = "Success" ErrorInvalidMethod = "ErrorInvalidMethod" ErrorInvalidRequest = "ErrorInvalidRequest" ErrorMissingRequired = "ErrorMissingRequired" Error = "Error" ErrorNoData = "ErrorNoData" ErrorUptodate = "ErrorUptodate" ErrorNoPermission = "ErrorNoPermission" ErrorInvalidMutation = "ErrorInvalidMutation" ValidHostnameRegex = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$" // When changing this value also remember to change in in client/client.go:DeleteEdges. Star = "_STAR_ALL" GrpcMaxSize = 256 << 20 // The attr used to store list of predicates for a node. PredicateListAttr = "_predicate_" PortInternal = 7080 PortHTTP = 8080 PortGrpc = 9080 )
Error constants representing different types of errors.
Variables ¶
var ( // These are cummulative PostingReads *expvar.Int PostingWrites *expvar.Int BytesRead *expvar.Int BytesWrite *expvar.Int EvictedPls *expvar.Int NumQueries *expvar.Int CacheHit *expvar.Int CacheMiss *expvar.Int CacheRace *expvar.Int // value at particular point of time PendingQueries *expvar.Int PendingProposals *expvar.Int LcacheSize *expvar.Int LcacheLen *expvar.Int LcacheCapacity *expvar.Int DirtyMapSize *expvar.Int NumGoRoutines *expvar.Int MemoryInUse *expvar.Int HeapIdle *expvar.Int TotalMemory *expvar.Int TotalOSMemory *expvar.Int ActiveMutations *expvar.Int ServerHealth *expvar.Int MaxPlSize *expvar.Int MaxPlLength *expvar.Int PredicateStats *expvar.Map Conf *expvar.Map MaxPlSz int64 )
var (
Logger = log.New(os.Stderr, "", log.Lshortfile|log.Flags())
)
var Nilbyte []byte
var WhiteSpace = strings.NewReplacer(" ", "", "\t", "")
WhiteSpace Replacer removes spaces and tabs from a string.
Functions ¶
func AddCorsHeaders ¶ added in v0.8.3
func AddCorsHeaders(w http.ResponseWriter)
func AddInit ¶ added in v0.4.4
func AddInit(f func())
AddInit adds a function to be run in x.Init, which should be called at the beginning of all mains.
func AppendProtoMsg ¶ added in v0.8.3
func AppendProtoMsg(p []byte, msg ProtoMessage) ([]byte, error)
func AppendUvarint ¶ added in v0.8.3
func AssertTrue ¶ added in v0.7.0
func AssertTrue(b bool)
AssertTrue asserts that b is true. Otherwise, it would log fatal.
func AssertTruef ¶ added in v0.7.0
AssertTruef is AssertTrue with extra info.
func AssertTruefNoTrace ¶ added in v0.8.2
func BuildDetails ¶ added in v0.9.0
func BuildDetails() string
func Check2 ¶ added in v0.7.0
func Check2(_ interface{}, err error)
Check2 acts as convenience wrapper around Check, using the 2nd argument as error.
func GenerateTLSConfig ¶ added in v0.8.2
func GenerateTLSConfig(config TLSHelperConfig) (tlsCfg *tls.Config, reloadConfig func(), err error)
GenerateTLSConfig creates and returns a new *tls.Config with the configuration provided. If the ConfigType provided in TLSHelperConfig is TLSServerConfig, it's return a reload function. If any problem is found, an error is returned
func HealthCheck ¶ added in v0.8.2
func HealthCheck() error
HealthCheck returns whether the server is ready to accept requests or not Load balancer would add the node to the endpoint once health check starts returning true
func Init ¶ added in v0.4.4
func Init(debug bool)
Init initializes flags and run all functions in initFunc.
func LoadTLSConfig ¶ added in v0.9.3
func LoadTLSConfig(conf *TLSHelperConfig, v *viper.Viper)
func PageRange ¶ added in v0.8.2
PageRange returns start and end indices given pagination params. Note that n is the size of the input list.
func ParseRequest ¶
func ParseRequest(w http.ResponseWriter, r *http.Request, data interface{}) bool
func PredicatePrefix ¶ added in v0.8.3
PredicatePrefix returns the prefix for all keys belonging to this predicate except schema key.
func PrintVersionOnly ¶ added in v0.4.3
func PrintVersionOnly()
PrintVersionOnly prints version and other helpful information if --version.
func Printf ¶ added in v0.7.0
func Printf(format string, args ...interface{})
Printf does a log.Printf. We often do printf for debugging but has to keep adding import "fmt" or "log" and removing them after we are done. Let's add Printf to "x" and include "x" almost everywhere. Caution: Do remember to call x.Init. For tests, you need a TestMain that calls x.Init.
func ReadLine ¶ added in v0.7.0
Reads a single line from a buffered reader. The line is read into the passed in buffer to minimize allocations. This is the preferred method for loading long lines which could be longer than the buffer size of bufio.Scanner.
func RegisterTLSFlags ¶ added in v0.9.3
func RemoveDuplicates ¶ added in v0.8.2
sorts the slice of strings and removes duplicates. changes the input slice. this function should be called like: someSlice = x.RemoveDuplicates(someSlice)
func Reply ¶
func Reply(w http.ResponseWriter, rep interface{})
func ReserveCap ¶ added in v0.8.3
func ReverseKey ¶ added in v0.7.1
func Round ¶ added in v0.7.3
Go doesn't have a round function for Duration and the duration value can be a bit ugly to look at sometimes. This is an attempt to round the value.
func SchemaKey ¶ added in v0.7.3
SchemaKey returns schema key for given attribute, schema keys are stored separately with unique prefix, since we need to iterate over all schema keys
func SchemaPrefix ¶ added in v0.7.3
func SchemaPrefix() []byte
SchemaPrefix returns the prefix for Schema keys.
func SetStatus ¶
func SetStatus(w http.ResponseWriter, code, msg string)
SetStatus sets the error code, message and the newly assigned uids in the http response.
func SetStatusWithData ¶ added in v0.8.2
func SetStatusWithData(w http.ResponseWriter, code, msg string)
In case an error was encountered after the query execution started, we have to return data key with null value according to GraphQL spec.
func SetTestRun ¶ added in v0.7.2
func SetTestRun()
func StartProfile ¶ added in v0.9.3
func UpdateHealthStatus ¶ added in v0.8.2
func UpdateHealthStatus(ok bool)
func UpdateMemoryStatus ¶ added in v0.8.2
func UpdateMemoryStatus(ok bool)
func ValidateAddress ¶ added in v0.8.2
ValidateAddress checks whether given address can be used with grpc dial function
Types ¶
type BytesBuffer ¶ added in v0.8.2
type BytesBuffer struct {
// contains filtered or unexported fields
}
func (*BytesBuffer) CopyTo ¶ added in v0.8.2
func (b *BytesBuffer) CopyTo(o []byte) int
Caller should ensure that o is of appropriate length
func (*BytesBuffer) Length ¶ added in v0.8.2
func (b *BytesBuffer) Length() int
func (*BytesBuffer) Slice ¶ added in v0.8.2
func (b *BytesBuffer) Slice(n int) []byte
returns a slice of lenght n to be used to writing
func (*BytesBuffer) TruncateBy ¶ added in v0.8.2
func (b *BytesBuffer) TruncateBy(n int)
Always give back <= touched bytes
type Histogram ¶ added in v0.8.2
A Histogram collects observed values by keeping bucketed counts. For convenience, intern.y two sets of buckets are kept: A cumulative set (i.e. data is never evicted) and a windowed set (which keeps only recently collected samples).
Top-level methods generally apply to the cumulative buckets; the windowed variant is exposed through the Windowed method.
func NewHistogram ¶ added in v0.8.2
NewHistogram initializes a given Histogram. The contained windowed histogram rotates every 'duration'; both the windowed and the cumulative histogram track nonnegative values up to 'maxVal' with 'sigFigs' decimal points of precision.
func (*Histogram) RecordValue ¶ added in v0.8.2
RecordValue adds the given value to the histogram. Recording a value in excess of the configured maximum value for that histogram results in recording the maximum value instead.
type ParsedKey ¶ added in v0.7.0
type ParsedKey struct { Attr string Uid uint64 Term string Count uint32 // contains filtered or unexported fields }
func (ParsedKey) CountPrefix ¶ added in v0.8.2
CountPrefix returns the prefix for count keys.
func (ParsedKey) DataPrefix ¶ added in v0.7.2
DataPrefix returns the prefix for data keys.
func (ParsedKey) IndexPrefix ¶ added in v0.7.0
IndexPrefix returns the prefix for index keys.
func (ParsedKey) ReversePrefix ¶ added in v0.8.2
ReversePrefix returns the prefix for index keys.
func (ParsedKey) SkipPredicate ¶ added in v0.7.0
func (ParsedKey) SkipRangeOfSameType ¶ added in v0.7.0
func (ParsedKey) SkipSchema ¶ added in v0.7.3
type ProtoMessage ¶ added in v0.8.3
type QueryResWithData ¶ added in v0.8.2
type QueryResWithData struct { Errors []errRes `json:"errors"` Data *string `json:"data"` }
type RaftValue ¶ added in v0.7.1
RaftValue contains the raft group and the raft proposal id. This is attached to the context, so the information could be passed down to the many posting lists, involved in mutations.
type SafeMutex ¶ added in v0.7.0
type SafeMutex struct {
// contains filtered or unexported fields
}
SafeLock can be used in place of sync.RWMutex
func (*SafeMutex) AssertLock ¶ added in v0.7.0
func (s *SafeMutex) AssertLock()
func (*SafeMutex) AssertRLock ¶ added in v0.7.0
func (s *SafeMutex) AssertRLock()
type SubCommand ¶ added in v0.9.3
type TLSHelperConfig ¶ added in v0.8.2
type TLSHelperConfig struct { ConfigType tlsConfigType CertRequired bool Cert string Key string KeyPassphrase string ServerName string Insecure bool RootCACerts string UseSystemRootCACerts bool ClientAuth string ClientCACerts string UseSystemClientCACerts bool MinVersion string MaxVersion string }
TLSHelperConfig define params used to create a tls.Config
type Throttle ¶ added in v0.8.2
type Throttle struct {
// contains filtered or unexported fields
}
Throttle allows a limited number of workers to run at a time. It also provides a mechanism to wait for all workers to finish.
func NewThrottle ¶ added in v0.8.2
NewThrottle creates a new throttle with a max number of workers.
func (*Throttle) Done ¶ added in v0.8.2
func (t *Throttle) Done()
Done should be called by workers when they finish working. It panics if there wasn't a corresponding Start call.
type ValueTypeInfo ¶ added in v0.8.2
type ValueTypeInfo int32
const ( ValueUnknown ValueTypeInfo = iota // unknown type of value ValueEmpty // no UID and no value ValueUid // UID ValuePlain // plain old value without defined language tag // Value which is part of a multi-value posting list (like language). ValueMulti )
Type of a data inside DirectedEdge, Posting or NQuad
func ValueType ¶ added in v0.8.2
func ValueType(hasValue, hasLang, hasSpecialId bool) ValueTypeInfo
Helper function, to decide value type of DirectedEdge/Posting/NQuad
type WaterMark ¶ added in v0.7.1
type WaterMark struct { Name string // contains filtered or unexported fields }
WaterMark is used to keep track of the minimum un-finished index. Typically, an index k becomes finished or "done" according to a WaterMark once Done(k) has been called
- as many times as Begin(k) has, AND
- a positive number of times.
An index may also become "done" by calling SetDoneUntil at a time such that it is not inter-mingled with Begin/Done calls.
func (*WaterMark) DoneUntil ¶ added in v0.7.1
DoneUntil returns the maximum index until which all tasks are done.
func (*WaterMark) Init ¶ added in v0.7.1
func (w *WaterMark) Init()
Init initializes a WaterMark struct. MUST be called before using it.