x

package
v0.7.2-1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2017 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package x contains some very common utilities used by Dgraph. These utilities are of "miscellaneous" nature, e.g., error checking.

Index

Constants

View Source
const (
	Success              = "Success"
	ErrorUnauthorized    = "ErrorUnauthorized"
	ErrorInvalidMethod   = "ErrorInvalidMethod"
	ErrorInvalidRequest  = "ErrorInvalidRequest"
	ErrorMissingRequired = "ErrorMissingRequired"
	Error                = "Error"
	ErrorNoData          = "ErrorNoData"
	ErrorUptodate        = "ErrorUptodate"
	ErrorNoPermission    = "ErrorNoPermission"
	ErrorInvalidMutation = "ErrorInvalidMutation"
)

Error constants representing different types of errors.

Variables

View Source
var Nilbyte []byte
View Source
var WhiteSpace = strings.NewReplacer(" ", "", "\t", "")

WhiteSpace Replacer removes spaces and tabs from a string.

Functions

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 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

func AssertTruef(b bool, format string, args ...interface{})

AssertTruef is AssertTrue with extra info.

func Check added in v0.7.0

func Check(err error)

Check logs fatal if err != nil.

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 Check2f added in v0.7.0

func Check2f(_ interface{}, err error, format string, args ...interface{})

Check2f acts as convenience wrapper around Checkf, using the 2nd argument as error.

func Checkf added in v0.7.0

func Checkf(err error, format string, args ...interface{})

Checkf is Check with extra info.

func DataKey added in v0.7.0

func DataKey(attr string, uid uint64) []byte

func Err

func Err(entry *logrus.Entry, err error) *logrus.Entry

func Errorf added in v0.7.0

func Errorf(format string, args ...interface{}) error

Errorf creates a new error with stack trace, etc.

func Fatalf added in v0.7.0

func Fatalf(format string, args ...interface{})

Fatalf logs fatal.

func IndexKey added in v0.7.0

func IndexKey(attr, term string) []byte

func Init added in v0.4.4

func Init()

Init initializes flags and run all functions in initFunc.

func IsTestRun added in v0.7.2

func IsTestRun() bool

func Log

func Log(p string) *logrus.Entry

func ParseRequest

func ParseRequest(w http.ResponseWriter, r *http.Request, data interface{}) bool

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

func ReadLine(r *bufio.Reader, buf *bytes.Buffer) error

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 Reply

func Reply(w http.ResponseWriter, rep interface{})

func ReverseKey added in v0.7.1

func ReverseKey(attr string, uid uint64) []byte

func SetError

func SetError(prev *error, n error)

SetError sets the error logged in this package.

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 SetTestRun added in v0.7.2

func SetTestRun()

func Trace

func Trace(ctx context.Context, format string, args ...interface{})

func TraceError added in v0.7.0

func TraceError(ctx context.Context, err error)

TraceError is like Trace but it logs just an error, which may have stacktrace.

func Wrap added in v0.7.0

func Wrap(err error) error

Wrap wraps errors from external lib.

func Wrapf added in v0.7.0

func Wrapf(err error, format string, args ...interface{}) error

Wrapf is Wrap with extra info.

Types

type Mark added in v0.7.1

type Mark struct {
	Index   uint64
	Indices []uint64
	Done    bool // Set to true if the pending mutation is done.
}

Mark contains raft proposal id and a done boolean. It is used to update the WaterMark struct about the status of a proposal.

type ParsedKey added in v0.7.0

type ParsedKey struct {
	Attr string
	Uid  uint64
	Term string
	// contains filtered or unexported fields
}

func Parse added in v0.7.0

func Parse(key []byte) *ParsedKey

func (ParsedKey) DataPrefix added in v0.7.2

func (p ParsedKey) DataPrefix() []byte

DataPrefix returns the prefix for data keys.

func (ParsedKey) IndexPrefix added in v0.7.0

func (p ParsedKey) IndexPrefix() []byte

IndexPrefix returns the prefix for index keys.

func (ParsedKey) IsData added in v0.7.0

func (p ParsedKey) IsData() bool

func (ParsedKey) IsIndex added in v0.7.0

func (p ParsedKey) IsIndex() bool

func (ParsedKey) IsReverse added in v0.7.1

func (p ParsedKey) IsReverse() bool

func (ParsedKey) SkipPredicate added in v0.7.0

func (p ParsedKey) SkipPredicate() []byte

func (ParsedKey) SkipRangeOfSameType added in v0.7.0

func (p ParsedKey) SkipRangeOfSameType() []byte

type RaftValue added in v0.7.1

type RaftValue struct {
	Group uint32
	Index uint64
}

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()

func (*SafeMutex) Lock added in v0.7.0

func (s *SafeMutex) Lock()

func (*SafeMutex) RLock added in v0.7.0

func (s *SafeMutex) RLock()

func (*SafeMutex) RUnlock added in v0.7.0

func (s *SafeMutex) RUnlock()

func (*SafeMutex) StartWait added in v0.7.0

func (s *SafeMutex) StartWait() *SafeWait

func (*SafeMutex) Unlock added in v0.7.0

func (s *SafeMutex) Unlock()

func (*SafeMutex) Wait added in v0.7.0

func (s *SafeMutex) Wait()

type SafeWait added in v0.7.0

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

func (*SafeWait) Done added in v0.7.0

func (s *SafeWait) Done()

type Status

type Status struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type WaterMark added in v0.7.1

type WaterMark struct {
	Name string
	Ch   chan Mark
	// contains filtered or unexported fields
}

WaterMark is used to keep track of the maximum done index. The right way to use this is to send a Mark with Done set to false, as soon as an index is known. WaterMark will store the index in a min-heap. It would only advance, if the minimum entry in the heap has been successfully done.

Some time later, when this index task is completed, send another Mark, this time with Done set to true. It would mark the index as done, and so the min-heap can now advance and update the maximum done water mark.

func (*WaterMark) DoneUntil added in v0.7.1

func (w *WaterMark) DoneUntil() uint64

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.

func (*WaterMark) WaitingFor added in v0.7.2

func (w *WaterMark) WaitingFor() bool

WaitingFor returns whether we are waiting for a task to be done.

Jump to

Keyboard shortcuts

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