Documentation
¶
Overview ¶
Package x contains some very common utilities used by Dgraph. These utilities are of "miscellaneous" nature, e.g., error checking.
Index ¶
- Constants
- Variables
- func AddCorsHeaders(w http.ResponseWriter)
- func AllACLPredicates() []string
- func AskUserPassword(userid string, pwdType string, times int) (string, error)
- func AssertTrue(b bool)
- func AssertTruef(b bool, format string, args ...interface{})
- func AssertTruefNoTrace(b bool, format string, args ...interface{})
- func AttachAccessJwt(ctx context.Context, r *http.Request) context.Context
- func AttachAuthToken(ctx context.Context, r *http.Request) context.Context
- func AttachJWTNamespace(ctx context.Context) context.Context
- func AttachJWTNamespaceOutgoing(ctx context.Context) (context.Context, error)
- func AttachNamespace(ctx context.Context, namespace uint64) context.Context
- func AttachNamespaceOutgoing(ctx context.Context, namespace uint64) context.Context
- func AttachRemoteIP(ctx context.Context, r *http.Request) context.Context
- func AttachRootNsOperation(ctx context.Context, ns uint64) context.Context
- func AttrFrom2103(attr string) (string, error)
- func AttrInRootNamespace(attr string) string
- func BuildDetails() string
- func BuildEncFlag(filename string) string
- func Check(err error)
- func Check2(_ interface{}, err error)
- func Checkf(err error, format string, args ...interface{})
- func CheckfNoLog(err error)
- func CheckfNoTrace(err error)
- func Codename() string
- func CountKey(attr string, count uint32, reverse bool) []byte
- func DataKey(attr string, uid uint64) []byte
- func DataPrefix(ns uint64) []byte
- func DeepCopyJsonArray(a []interface{}) []interface{}
- func DeepCopyJsonMap(m map[string]interface{}) map[string]interface{}
- func DevVersion() (matched bool)
- func Diff(dst map[string]struct{}, src map[string]struct{}) ([]string, []string)
- func DivideAndRule(num int) (numGo, width int)
- func ExecutableChecksum() []byte
- func ExponentialRetry(maxRetries int, waitAfterFailure time.Duration, f func() error) error
- func ExtractJwt(ctx context.Context) (string, error)
- func ExtractNamespace(ctx context.Context) (uint64, error)
- func ExtractNamespaceFrom(ctx context.Context) (uint64, error)
- func ExtractNamespaceFromJwt(jwtToken string) (uint64, error)
- func ExtractNamespaceHTTP(r *http.Request) uint64
- func ExtractUserName(jwtToken string) (string, error)
- func Fatalf(format string, args ...interface{})
- func FillCommonFlags(flag *pflag.FlagSet)
- func FindDataFiles(str string, ext []string) []string
- func FindFilesFunc(dir string, f func(string) bool) []string
- func FixedDuration(d time.Duration) string
- func FromBackupKey(backupKey *pb.BackupKey) []byte
- func GenerateClientTLSConfig(config *TLSHelperConfig) (tlsCfg *tls.Config, err error)
- func GenerateServerTLSConfig(config *TLSHelperConfig) (tlsCfg *tls.Config, err error)
- func GetCachePercentages(cpString string, numExpected int) ([]int64, error)
- func GetForceNamespace(ctx context.Context) string
- func GetPassAndLogin(dg *dgo.Dgraph, opt *CredOpt) error
- func GetRandomName(retry int) string
- func HasString(a []string, b string) bool
- func HasWhitelistedIP(ctx context.Context) (net.Addr, error)
- func HealthCheck() error
- func Ignore(_ error)
- func IndexKey(attr, term string) []byte
- func IsAclPredicate(pred string) bool
- func IsDropOpKey(key []byte) (bool, error)
- func IsGqlErrorList(err error) bool
- func IsInternalPredicate(pred string) bool
- func IsJwtExpired(err error) bool
- func IsMissingOrEmptyDir(path string) (err error)
- func IsOtherReservedPredicate(pred string) bool
- func IsPreDefinedPredicate(pred string) bool
- func IsPreDefinedType(typ string) bool
- func IsReservedPredicate(pred string) bool
- func IsReservedType(typ string) bool
- func IsReverseAttr(attr string) bool
- func IsRootNsOperation(ctx context.Context) bool
- func IsSuperAdmin(groups []string) bool
- func JemallocHandler(w http.ResponseWriter, r *http.Request)
- func KvWithMaxVersion(kvs *badgerpb.KVList, prefixes [][]byte) *badgerpb.KV
- func LambdaUrl(ns uint64) string
- func LoadClientTLSConfig(v *viper.Viper) (*tls.Config, error)
- func LoadClientTLSConfigForInternalPort(v *viper.Viper) (*tls.Config, error)
- func LoadServerTLSConfig(v *viper.Viper) (*tls.Config, error)
- func LoadServerTLSConfigForInternalPort(v *viper.Viper) (*tls.Config, error)
- func Log(err error, msg string)
- func MarshalToSizedBuffer(buf []byte, m proto.Message) ([]byte, error)
- func Max(a, b uint64) uint64
- func MaybeKeyToBytes(k interface{}) interface{}
- func MetricsContext() context.Context
- func Min(a, b uint64) uint64
- func MinioCredentialsProvider(scheme string, requestCreds credentials.Value) credentials.Provider
- func MinioCredentialsProviderWithoutEnv(requestCreds credentials.Value) credentials.Provider
- func MonitorCacheHealth(db *badger.DB, closer *z.Closer)
- func MonitorDiskMetrics(dirTag string, dir string, lc *z.Closer)
- func MonitorMemoryMetrics(lc *z.Closer)
- func NamespaceAttr(ns uint64, attr string) string
- func NamespaceAttrList(ns uint64, preds []string) []string
- func NamespaceToBytes(ns uint64) []byte
- func NewBadgerCollector() prometheus.Collector
- func PageRange(count, offset, n int) (int, int)
- func Panic(err error)
- func ParseAttr(attr string) string
- func ParseAttrList(attrs []string) []string
- func ParseCompression(cStr string) (bo.CompressionType, int)
- func ParseJWT(jwtStr string) (jwt.MapClaims, error)
- func ParseNamespace(attr string) uint64
- func ParseNamespaceAttr(attr string) (uint64, string)
- func ParseNamespaceBytes(attr string) ([]byte, string)
- func ParseRequest(w http.ResponseWriter, r *http.Request, data interface{}) bool
- func PredicateLang(s string) (string, string)
- func PredicatePrefix(predicate string) []byte
- func PrefixesToMatches(prefixes [][]byte, ignore string) []*badgerpb.Match
- func PrintMutationEdge(plist *pb.DirectedEdge, key ParsedKey, startTs uint64)
- func PrintOracleDelta(delta *pb.OracleDelta)
- func PrintRollup(plist *pb.PostingList, parts map[uint64]*pb.PostingList, baseKey []byte, ...)
- func PrintVersion()
- func ProposalKey(id uint64) (uint64, error)
- func QueryMaxOpenFiles() (int, error)
- func ReadGroupIdFile(pdir string) (uint32, error)
- func ReadLine(r *bufio.Reader, buf *bytes.Buffer) error
- func RegisterAclAndEncFlags(flag *pflag.FlagSet)
- func RegisterClientTLSFlags(flag *pflag.FlagSet)
- func RegisterEncFlag(flag *pflag.FlagSet)
- func RegisterExporters(conf *viper.Viper, service string)
- func RegisterServerTLSFlags(flag *pflag.FlagSet)
- func RemoveDuplicates(s []string) (out []string)
- func Reply(w http.ResponseWriter, rep interface{})
- func RetryUntilSuccess(maxRetries int, waitAfterFailure time.Duration, f func() error) error
- func ReverseKey(attr string, uid uint64) []byte
- func RunVlogGC(store *badger.DB, closer *z.Closer)
- func SchemaKey(attr string) []byte
- func SchemaPrefix() []byte
- func SetHttpStatus(w http.ResponseWriter, code int, msg string)
- func SetStatus(w http.ResponseWriter, code, msg string)
- func SetStatusWithData(w http.ResponseWriter, code, msg string)
- func SetStatusWithErrors(w http.ResponseWriter, code string, errs []string)
- func SetupConnection(host string, tlsCfg *tls.Config, useGz bool, dialOpts ...grpc.DialOption) (*grpc.ClientConn, error)
- func ShouldCrash(err error) bool
- func SinceMs(startTime time.Time) float64
- func SlashTLSConfig(endpoint string) (*tls.Config, error)
- func SpanTimer(spanInterface interface{}, name string) func()
- func SplitKey(baseKey []byte, startUid uint64) ([]byte, error)
- func StarAllPredicates(namespace uint64) []string
- func StartListenHttpAndHttps(l net.Listener, tlsCfg *tls.Config, closer *z.Closer)
- func StoreSync(db DB, closer *z.Closer)
- func TLSBaseConfig() *tls.Config
- func ToHex(i uint64, rdf bool) []byte
- func TypeKey(attr string) []byte
- func TypePrefix() []byte
- func Unique(a []string) []string
- func UpdateDrainingMode(enable bool)
- func UpdateHealthStatus(ok bool)
- func ValidateAddress(addr string) error
- func VerifyPack(plist *pb.PostingList)
- func VerifyPostingSplits(kvs []*bpb.KV, plist *pb.PostingList, parts map[uint64]*pb.PostingList, ...)
- func VerifySnapshot(pstore *badger.DB, readTs uint64)
- func Version() string
- func WalkPathFunc(dir string, f func(string, bool) bool) []string
- func WithAuthorizationCredentials(authToken string) grpc.DialOption
- func WithMethod(parent context.Context, method string) context.Context
- func WriteFileSync(filename string, data []byte, perm os.FileMode) error
- func WriteGroupIdFile(pdir string, group_id uint32) error
- func WriteResponse(w http.ResponseWriter, r *http.Request, b []byte) (int, error)
- type BytesBuffer
- type CloseFunc
- type CredOpt
- type DB
- type ExportedGQLSchema
- type GqlError
- type GqlErrorList
- type Histogram
- type IPRange
- type Keys
- type LimiterConf
- type Location
- type LogWriter
- type Logger
- type LoggerConf
- type MinioClient
- type MinioCredentials
- 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) IsCountOrCountRev() bool
- func (p ParsedKey) IsCountRev() bool
- func (p ParsedKey) IsData() bool
- func (p ParsedKey) IsIndex() bool
- func (p ParsedKey) IsOfType(typ byte) bool
- func (p ParsedKey) IsReverse() bool
- func (p ParsedKey) IsSchema() bool
- func (p ParsedKey) IsType() bool
- func (p ParsedKey) ReversePrefix() []byte
- func (p ParsedKey) SkipPredicate() []byte
- func (p ParsedKey) String() string
- func (p ParsedKey) ToBackupKey() *pb.BackupKey
- type QueryResWithData
- type RateLimiter
- type SafeMutex
- type Sensitive
- type Stopper
- type SubCommand
- type TLSHelperConfig
- type Timer
- type ToGlog
- func (rl *ToGlog) Debug(v ...interface{})
- func (rl *ToGlog) Debugf(format string, v ...interface{})
- func (rl *ToGlog) Error(v ...interface{})
- func (rl *ToGlog) Errorf(format string, v ...interface{})
- func (rl *ToGlog) Fatal(v ...interface{})
- func (rl *ToGlog) Fatalf(format string, v ...interface{})
- func (rl *ToGlog) Info(v ...interface{})
- func (rl *ToGlog) Infof(format string, v ...interface{})
- func (rl *ToGlog) Panic(v ...interface{})
- func (rl *ToGlog) Panicf(format string, v ...interface{})
- func (rl *ToGlog) Warning(v ...interface{})
- func (rl *ToGlog) Warningf(format string, v ...interface{})
- type ValueTypeInfo
- type WorkerOptions
Constants ¶
const ( TraceDefaults = `ratio=0.01; jaeger=; datadog=;` TelemetryDefaults = `reports=true;sentry=false;` )
const ( // ByteData indicates the key stores data. ByteData = byte(0x00) // ByteIndex indicates the key stores an index. ByteIndex = byte(0x02) // ByteReverse indicates the key stores a reverse index. ByteReverse = byte(0x04) // ByteCount indicates the key stores a count index. ByteCount = byte(0x08) // ByteCountRev indicates the key stores a reverse count index. ByteCountRev = ByteCount | ByteReverse // DefaultPrefix is the prefix used for data, index and reverse keys so that relative // order of data doesn't change keys of same attributes are located together. DefaultPrefix = byte(0x00) ByteSchema = byte(0x01) ByteType = byte(0x02) // ByteSplit signals that the key stores an individual part of a multi-part list. ByteSplit = byte(0x04) // ByteUnused is a constant to specify keys which need to be discarded. ByteUnused = byte(0xff) // RootNamespace is the default namespace name. RootNamespace = uint64(0) // IgnoreBytes is the byte range which will be ignored while prefix match in subscription. IgnoreBytes = "1-8" // NamespaceOffset is the offset in badger key from which the next 8 bytes contain namespace. NamespaceOffset = 1 // NsSeparator is the separator between the namespace and attribute. NsSeparator = "-" )
const ( // old logs before https://github.com/hypermodeinc/dgraph/pull/8323 contain deprecated verification text in header VerificationTextDeprecated = "Hello World" VerificationText = "dlroW olloH" )
const ( TLSDefaults = `use-system-ca=true; client-auth-type=VERIFYIFGIVEN; internal-port=false; ` + `ca-cert=; server-name=; server-cert=; server-key=; client-cert=; client-key=;` TLSServerDefaults = `use-system-ca=true; client-auth-type=VERIFYIFGIVEN; internal-port=false; ` + `server-cert=; server-key=; ca-cert=; client-cert=; client-key=;` TLSClientDefaults = `use-system-ca=true; internal-port=false; server-name=; ca-cert=; ` + `client-cert=; client-key=;` )
const ( // Success is equivalent to the HTTP 200 error code. Success = "Success" ErrorUnauthorized = "ErrorUnauthorized" // ErrorInvalidMethod is equivalent to the HTTP 405 error code. ErrorInvalidMethod = "ErrorInvalidMethod" // ErrorInvalidRequest is equivalent to the HTTP 400 error code. ErrorInvalidRequest = "ErrorInvalidRequest" // Error is a general error code. Error = "Error" // ErrorNoData is an error returned when the requested data cannot be returned. ErrorNoData = "ErrorNoData" // ValidHostnameRegex is a regex that accepts our expected hostname format. ValidHostnameRegex = `^([a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}` + `[a-zA-Z0-9_-]{0,62})*[._]?$` // Star is equivalent to using * in a mutation. // When changing this value also remember to change in in client/client.go:DeleteEdges. Star = "_STAR_ALL" // GrpcMaxSize is the maximum possible size for a gRPC message. // Dgraph uses the maximum size for the most flexibility (2GB - equal // to the max grpc frame size). Users will still need to set the max // message sizes allowable on the client size when dialing. GrpcMaxSize = math.MaxInt32 // PortZeroGrpc is the default gRPC port for zero. PortZeroGrpc = 5080 // PortZeroHTTP is the default HTTP port for zero. PortZeroHTTP = 6080 // PortInternal is the default port for internal use. PortInternal = 7080 // PortHTTP is the default HTTP port for alpha. PortHTTP = 8080 // PortGrpc is the default gRPC port for alpha. PortGrpc = 9080 // ForceAbortDifference is the maximum allowed difference between // AppliedUntil - TxnMarks.DoneUntil() before old transactions start getting aborted. ForceAbortDifference = 5000 // FacetDelimiter is the symbol used to distinguish predicate names from facets. FacetDelimiter = "|" // GrootId is the ID of the admin user for ACLs. GrootId = "groot" // SuperAdminId is the ID of the admin group for ACLs. SuperAdminId = "guardians" // GroupIdFileName is the name of the file storing the ID of the group to which // the data in a postings directory belongs. This ID is used to join the proper // group the first time an Alpha comes up with data from a restored backup or a // bulk load. GroupIdFileName = "group_id" // DefaultCreds is the default credentials for login via dgo client. DefaultCreds = "user=; password=; namespace=0;" AccessControlAllowedHeaders = "X-Dgraph-AccessToken, X-Dgraph-AuthToken, " + "Content-Type, Content-Length, Accept-Encoding, Cache-Control, " + "X-CSRF-Token, X-Auth-Token, X-Requested-With" DgraphCostHeader = "Dgraph-TouchedUids" ManifestVersion = 2105 )
Variables ¶
var ( // NumQueries is the total number of queries processed so far. NumQueries = ostats.Int64("num_queries_total", "Total number of queries", ostats.UnitDimensionless) // NumMutations is the total number of mutations processed so far. NumMutations = ostats.Int64("num_mutations_total", "Total number of mutations", ostats.UnitDimensionless) // NumEdges is the total number of edges created so far. NumEdges = ostats.Int64("num_edges_total", "Total number of edges created", ostats.UnitDimensionless) // NumBackups is the number of backups requested NumBackups = ostats.Int64("num_backups_total", "Total number of backups requested", ostats.UnitDimensionless) // NumBackupsSuccess is the number of backups successfully completed NumBackupsSuccess = ostats.Int64("num_backups_success_total", "Total number of backups completed", ostats.UnitDimensionless) // NumBackupsFailed is the number of backups failed NumBackupsFailed = ostats.Int64("num_backups_failed_total", "Total number of backups failed", ostats.UnitDimensionless) // LatencyMs is the latency of the various Dgraph operations. LatencyMs = ostats.Float64("latency", "Latency of the various methods", ostats.UnitMilliseconds) // BadgerReadLatencyMs is the latency of various different predicate reads from badger. BadgerReadLatencyMs = ostats.Float64("badger_read_latency_ms", "Latency of the various methods", ostats.UnitMilliseconds) // PendingQueries records the current number of pending queries. PendingQueries = ostats.Int64("pending_queries_total", "Number of pending queries", ostats.UnitDimensionless) // PendingProposals records the current number of pending RAFT proposals. PendingProposals = ostats.Int64("pending_proposals_total", "Number of pending proposals", ostats.UnitDimensionless) // PendingBackups records if a backup is currently in progress PendingBackups = ostats.Int64("pending_backups_total", "Number of backups", ostats.UnitDimensionless) // MemoryAlloc records the amount of memory allocated via jemalloc MemoryAlloc = ostats.Int64("memory_alloc_bytes", "Amount of memory allocated", ostats.UnitBytes) // MemoryInUse records the current amount of used memory by Dgraph. MemoryInUse = ostats.Int64("memory_inuse_bytes", "Amount of memory in use", ostats.UnitBytes) // MemoryIdle records the amount of memory held by the runtime but not in-use by Dgraph. MemoryIdle = ostats.Int64("memory_idle_bytes", "Amount of memory in idle spans", ostats.UnitBytes) // MemoryProc records the amount of memory used in processes. MemoryProc = ostats.Int64("memory_proc_bytes", "Amount of memory used in processes", ostats.UnitBytes) // DiskFree records the number of bytes free on the disk DiskFree = ostats.Int64("disk_free_bytes", "Total number of bytes free on disk", ostats.UnitBytes) // DiskUsed records the number of bytes free on the disk DiskUsed = ostats.Int64("disk_used_bytes", "Total number of bytes used on disk", ostats.UnitBytes) // DiskTotal records the number of bytes free on the disk DiskTotal = ostats.Int64("disk_total_bytes", "Total number of bytes on disk", ostats.UnitBytes) // ActiveMutations is the current number of active mutations. ActiveMutations = ostats.Int64("active_mutations_total", "Number of active mutations", ostats.UnitDimensionless) // AlphaHealth status records the current health of the alphas. AlphaHealth = ostats.Int64("alpha_health_status", "Status of the alphas", ostats.UnitDimensionless) // RaftAppliedIndex records the latest applied RAFT index. RaftAppliedIndex = ostats.Int64("raft_applied_index", "Latest applied Raft index", ostats.UnitDimensionless) RaftApplyCh = ostats.Int64("raft_applych_size", "Number of proposals in Raft apply channel", ostats.UnitDimensionless) RaftPendingSize = ostats.Int64("pending_proposal_bytes", "Size of Raft pending proposal", ostats.UnitBytes) // MaxAssignedTs records the latest max assigned timestamp. MaxAssignedTs = ostats.Int64("max_assigned_ts", "Latest max assigned timestamp", ostats.UnitDimensionless) // TxnCommits records count of committed transactions. TxnCommits = ostats.Int64("txn_commits_total", "Number of transaction commits", ostats.UnitDimensionless) // TxnDiscards records count of discarded transactions by the client. TxnDiscards = ostats.Int64("txn_discards_total", "Number of transaction discards by the client", ostats.UnitDimensionless) // TxnAborts records count of aborted transactions by the server. TxnAborts = ostats.Int64("txn_aborts_total", "Number of transaction aborts by the server", ostats.UnitDimensionless) // PBlockHitRatio records the hit ratio of posting store block cache. PBlockHitRatio = ostats.Float64("hit_ratio_postings_block", "Hit ratio of p store block cache", ostats.UnitDimensionless) // PIndexHitRatio records the hit ratio of posting store index cache. PIndexHitRatio = ostats.Float64("hit_ratio_postings_index", "Hit ratio of p store index cache", ostats.UnitDimensionless) // PLCacheHitRatio records the hit ratio of posting list cache. PLCacheHitRatio = ostats.Float64("hit_ratio_posting_cache", "Hit ratio of posting list cache", ostats.UnitDimensionless) // RaftHasLeader records whether this instance has a leader RaftHasLeader = ostats.Int64("raft_has_leader", "Whether or not a leader exists for the group", ostats.UnitDimensionless) // RaftIsLeader records whether this instance is the leader RaftIsLeader = ostats.Int64("raft_is_leader", "Whether or not this instance is the leader of the group", ostats.UnitDimensionless) // RaftLeaderChanges records the total number of leader changes seen. RaftLeaderChanges = ostats.Int64("raft_leader_changes_total", "Total number of leader changes seen", ostats.UnitDimensionless) NumPostingListCacheRead = ostats.Int64("num_posting_list_cache_reads", "Number of times cache was read", ostats.UnitDimensionless) NumPostingListCacheReadFail = ostats.Int64("num_posting_list_cache_reads_fail", "Number of times cache was read", ostats.UnitDimensionless) NumPostingListCacheSave = ostats.Int64("num_posting_list_cache_saves", "Number of times item was saved in cache", ostats.UnitDimensionless) // Conf holds the metrics config. // TODO: Request statistics, latencies, 500, timeouts Conf *expvar.Map // KeyGroup is the tag key used to record the group for Raft metrics. KeyGroup, _ = tag.NewKey("group") // KeyStatus is the tag key used to record the status of the server. KeyStatus, _ = tag.NewKey("status") // KeyMethod is the tag key used to record the method (e.g read or mutate). KeyMethod, _ = tag.NewKey("method") // KeyDirType is the tag key used to record the group for FileSystem metrics KeyDirType, _ = tag.NewKey("dir") // TagValueStatusOK is the tag value used to signal a successful operation. TagValueStatusOK = "ok" // TagValueStatusError is the tag value used to signal an unsuccessful operation. TagValueStatusError = "error" )
var ( AclDefaults = fmt.Sprintf("%s=%s; %s=%s; %s=%s; %s=%s", flagAclAccessTtl, "6h", flagAclRefreshTtl, "30d", flagAclJwtAlg, "HS256", flagAclKeyFile, "") EncDefaults = fmt.Sprintf("%s=%s", flagEncKeyFile, "") )
var ( // ErrNoJwt is returned when JWT is not present in the context. ErrNoJwt = errors.New("no accessJwt available") // ErrorInvalidLogin is returned when username or password is incorrect in login ErrorInvalidLogin = errors.New("invalid username or password") // ErrConflict is returned when commit couldn't succeed due to conflicts. ErrConflict = errors.New("Transaction conflict") // ErrHashMismatch is returned when the hash does not matches the startTs ErrHashMismatch = errors.New("hash mismatch the claimed startTs|namespace") )
Error constants representing different types of errors.
var ( // Nilbyte is a nil byte slice. Used Nilbyte []byte // SuperAdminUid is a map from namespace to the Uid of superadmin group node. SuperAdminUid = &sync.Map{} // GrootUid is a map from namespace to the Uid of groot user node. GrootUid = &sync.Map{} )
var ErrMissingDir = errors.Errorf("missing or empty directory")
ErrMissingDir is thrown by IsMissingOrEmptyDir if the given path is a missing or empty directory.
var NonRootTemplate string = `` /* 653-byte string literal not displayed */
NonRootTemplate defines the help template for dgraph sub-command.
var RootTemplate string = `Dgraph is a horizontally scalable and distributed graph database, providing ACID transactions, consistent replication and linearizable reads. It's built from the ground up to perform for a rich set of queries. Being a native graph database, it tightly controls how the data is arranged on disk to optimize for query performance and throughput, reducing disk seeks and network calls in a cluster.` + BuildDetails() + `Usage:{{if .Runnable}} {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}} {{.CommandPath}} [command]{{end}} {{if .HasAvailableSubCommands}} Generic: {{range .Commands}} {{if (or (and .IsAvailableCommand (eq .Annotations.group "default")) (eq .Name "help"))}} {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} Available Commands: Dgraph Core: {{range .Commands}} {{if (and .IsAvailableCommand (eq .Annotations.group "core"))}} {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} Data Loading: {{range .Commands}} {{if (and .IsAvailableCommand (eq .Annotations.group "data-load"))}} {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} Dgraph Security: {{range .Commands}} {{if (and .IsAvailableCommand (eq .Annotations.group "security"))}} {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} Dgraph Debug: {{range .Commands}} {{if (and .IsAvailableCommand (eq .Annotations.group "debug"))}} {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} Dgraph Tools: {{range .Commands}} {{if (and .IsAvailableCommand (eq .Annotations.group "tool"))}} {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} ` + ` Flags: {{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}} Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}} `
RootTemplate defines the help template for dgraph command.
var ( // ServerCloser is used to signal and wait for other goroutines to return gracefully after user // requests shutdown. ServerCloser = z.NewCloser(0) )
var WhiteSpace = strings.NewReplacer(" ", "", "\t", "")
WhiteSpace Replacer removes spaces and tabs from a string.
Functions ¶
func AddCorsHeaders ¶
func AddCorsHeaders(w http.ResponseWriter)
AddCorsHeaders adds the CORS headers to an HTTP response.
func AllACLPredicates ¶
func AllACLPredicates() []string
func AskUserPassword ¶
AskUserPassword prompts the user to enter the password for the given user ID.
func AssertTrue ¶
func AssertTrue(b bool)
AssertTrue asserts that b is true. Otherwise, it would log fatal.
func AssertTruef ¶
AssertTruef is AssertTrue with extra info.
func AssertTruefNoTrace ¶
AssertTruefNoTrace is AssertTruef without a stack trace.
func AttachAccessJwt ¶
AttachAccessJwt adds any incoming JWT header data into the grpc context metadata
func AttachAuthToken ¶
AttachAuthToken adds any incoming PoorMan's auth header data into the grpc context metadata
func AttachJWTNamespace ¶
AttachJWTNamespace attaches the namespace in the JWT claims to the context if present, otherwise it attaches the galaxy namespace.
func AttachJWTNamespaceOutgoing ¶
AttachJWTNamespaceOutgoing attaches the namespace in the JWT claims to the outgoing metadata of the context.
func AttachNamespace ¶
AttachNamespace adds given namespace to the metadata of the context.
func AttachNamespaceOutgoing ¶
AttachNamespaceOutgoing adds given namespace in the outgoing metadata of the context.
func AttachRemoteIP ¶
AttachRemoteIP adds any incoming IP data into the grpc context metadata
func AttachRootNsOperation ¶
AttachRootNsOperation specifies in the context that it will be used for doing a Root Namespace operation.
func AttrFrom2103 ¶
AttrFrom2103 parses namespace that were stored in format used before 21.03 version. The first 8 bytes are the namespace, rest is the predicate. This format caused issues while marshalling, hence was removed. This function is there for backwards compatibility of restore. Now we store the predicate as a string of format "hex(namespace)-predicate"
func AttrInRootNamespace ¶
func BuildDetails ¶
func BuildDetails() string
BuildDetails returns a string containing details about the Dgraph binary.
func BuildEncFlag ¶
func Check2 ¶
func Check2(_ interface{}, err error)
Check2 acts as convenience wrapper around Check, using the 2nd argument as error.
func CheckfNoLog ¶
func CheckfNoLog(err error)
CheckfNoLog exits on error without any message (to avoid duplicate error messages).
func CountKey ¶
CountKey generates a count key with the given attribute and uid. The structure of a count key is as follows:
byte 0: key type prefix (set to DefaultPrefix) byte 1-2: length of attr next len(attr) bytes: value of attr next byte: data type prefix (set to ByteCount or ByteCountRev) next four bytes: value of count.
func DataKey ¶
DataKey generates a data key with the given attribute and UID. The structure of a data key is as follows:
byte 0: key type prefix (set to DefaultPrefix or ByteSplit if part of a multi-part list) byte 1-2: length of attr next len(attr) bytes: value of attr next byte: data type prefix (set to ByteData) next eight bytes: value of uid next eight bytes (optional): if the key corresponds to a split list, the startUid of the split stored in this key and the first byte will be sets to ByteSplit.
func DataPrefix ¶
DataPrefix returns the prefix for all data keys belonging to this namespace.
func DeepCopyJsonArray ¶
func DeepCopyJsonArray(a []interface{}) []interface{}
DeepCopyJsonArray returns a deep copy of the input array `a`. `a` is supposed to be an array similar to the ones produced as a result of json unmarshalling. i.e., any value in `a` at any nested level should be of an inbuilt go type.
func DeepCopyJsonMap ¶
DeepCopyJsonMap returns a deep copy of the input map `m`. `m` is supposed to be a map similar to the ones produced as a result of json unmarshalling. i.e., any value in `m` at any nested level should be of an inbuilt go type.
func DevVersion ¶
func DevVersion() (matched bool)
DevVersion returns true if the version string contains the above pattern e.g.
- v2.0.0-rc1-127-gd20a768b3 => dev version
- v2.0.0 => prod version
func DivideAndRule ¶
DivideAndRule is used to divide a number of tasks among multiple go routines.
func ExecutableChecksum ¶
func ExecutableChecksum() []byte
ExecutableChecksum returns a byte slice containing the SHA256 checksum of the executable. It returns a nil slice if there's an error trying to calculate the checksum.
func ExponentialRetry ¶
ExponentialRetry runs the given function until it succeeds or can no longer be retried.
func ExtractNamespace ¶
ExtractNamespace parses the namespace value from the incoming gRPC context. For the non-ACL mode, it is caller's responsibility to set the galaxy namespace.
func ExtractNamespaceFromJwt ¶
func ExtractNamespaceHTTP ¶
ExtractNamespaceHTTP parses the namespace value from the incoming HTTP request.
func ExtractUserName ¶
func FillCommonFlags ¶
FillCommonFlags stores flags common to Alpha and Zero.
func FindDataFiles ¶
FindDataFiles returns a list of data files as a string array. If str is a comma-separated list of paths, it returns that list. If str is a single path that is not a directory, it returns that path. If str is a directory, it returns the files in it that have one of the extensions in ext.
func FindFilesFunc ¶
FindFilesFunc walks the directory 'dir' and collects all file names matched by func f. It will skip over directories. Returns empty string slice if nothing found, otherwise returns all matched file names.
func FixedDuration ¶
FixedDuration returns the given duration as a string of fixed length.
func FromBackupKey ¶
FromBackupKey takes a key in the format used for backups and converts it to a key.
func GenerateClientTLSConfig ¶
func GenerateClientTLSConfig(config *TLSHelperConfig) (tlsCfg *tls.Config, err error)
GenerateClientTLSConfig creates and returns a new client side *tls.Config with the configuration provided.
func GenerateServerTLSConfig ¶
func GenerateServerTLSConfig(config *TLSHelperConfig) (tlsCfg *tls.Config, err error)
GenerateServerTLSConfig creates and returns a new *tls.Config with the configuration provided.
func GetCachePercentages ¶
GetCachePercentages returns the slice of cache percentages given the "," (comma) separated cache percentages(integers) string and expected number of caches.
func GetForceNamespace ¶
func GetPassAndLogin ¶
GetPassAndLogin uses the given credentials and client to perform the login operation.
func GetRandomName ¶
GetRandomName generates a random name from the list of adjectives and surnames in this package formatted as "adjective_surname". For example 'focused_turing'. If retry is non-zero, a random integer between 0 and 10 will be added to the end of the name, e.g `focused_turing3`
func HasWhitelistedIP ¶
HasWhitelistedIP checks whether the source IP in ctx is whitelisted or not. It returns the IP address if the IP is whitelisted, otherwise an error is returned.
func HealthCheck ¶
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 Ignore ¶
func Ignore(_ error)
Ignore function is used to ignore errors deliberately, while keeping the linter happy.
func IndexKey ¶
IndexKey generates a index key with the given attribute and term. The structure of an index key is as follows:
byte 0: key type prefix (set to DefaultPrefix or ByteSplit if part of a multi-part list) byte 1-2: length of attr next len(attr) bytes: value of attr next byte: data type prefix (set to ByteIndex) next len(term) bytes: value of term next eight bytes (optional): if the key corresponds to a split list, the startUid of the split stored in this key.
func IsAclPredicate ¶
IsAclPredicate returns true if the predicate is in the list of reserved predicates for the ACL feature.
func IsDropOpKey ¶
func IsGqlErrorList ¶
IsGqlErrorList tells whether the given err is a list of GraphQL errors.
func IsInternalPredicate ¶
IsInternalPredicate returns true if the predicate is in the internal predicate list. Currently, `uid` is the only such candidate.
func IsJwtExpired ¶
IsJwtExpired returns true if the error indicates that the jwt has expired.
func IsMissingOrEmptyDir ¶
IsMissingOrEmptyDir returns true if the path either does not exist or is a directory that is empty.
func IsOtherReservedPredicate ¶
IsOtherReservedPredicate returns true if it is the predicate is reserved by graphql. These are a subset of PreDefined predicates, so follow all their properties. In addition, the value for these predicates is also not allowed to be mutated directly by the users.
func IsPreDefinedPredicate ¶
IsPreDefinedPredicate returns true only if the predicate has been defined by dgraph internally in the initial schema. These are not allowed to be dropped, as well as any schema update which is different than the initial internal schema is also not allowed for these. For example, `dgraph.type` or ACL predicates or GraphQL predicates are defined in the initial internal schema.
We reserve `dgraph.` as the namespace for the types/predicates we may create in future. So, users are not allowed to create a predicate under this namespace. Hence, we should always define internal predicates under `dgraph.` namespace.
Pre-defined predicates are subset of reserved predicates.
func IsPreDefinedType ¶
IsPreDefinedType returns true only if the typ has been defined by dgraph internally. For example, `dgraph.graphql` or ACL types are defined in the initial internal types.
We reserve `dgraph.` as the namespace for the types/predicates we may create in future. So, users are not allowed to create a predicate under this namespace. Hence, we should always define internal types under `dgraph.` namespace.
Pre-defined types are subset of reserved types.
func IsReservedPredicate ¶
IsReservedPredicate returns true if the predicate is reserved for internal usage, i.e., prefixed with `dgraph.`.
We reserve `dgraph.` as the namespace for the types/predicates we may create in future. So, users are not allowed to create a predicate under this namespace. Hence, we should always define internal predicates under `dgraph.` namespace.
Reserved predicates are a superset of pre-defined predicates.
When critical, use IsPreDefinedPredicate(pred string) to find out whether the predicate was actually defined internally or not.
As an example, consider below predicates:
- dgraph.type (reserved = true, pre_defined = true )
- dgraph.blah (reserved = true, pre_defined = false)
- person.name (reserved = false, pre_defined = false)
func IsReservedType ¶
IsReservedType returns true if the given typ is reserved for internal usage, i.e., prefixed with `dgraph.`.
We reserve `dgraph.` as the namespace for the types/predicates we may create in future. So, users are not allowed to create a type under this namespace. Hence, we should always define internal types under `dgraph.` namespace.
Pre-defined types are subset of reserved types.
When critical, use IsPreDefinedType(typ string) to find out whether the typ was actually defined internally or not.
func IsReverseAttr ¶
func IsRootNsOperation ¶
func IsSuperAdmin ¶
func JemallocHandler ¶
func JemallocHandler(w http.ResponseWriter, r *http.Request)
func KvWithMaxVersion ¶
KvWithMaxVersion returns a KV with the max version from the list of KVs.
func LoadClientTLSConfig ¶
LoadClientTLSConfig loads the TLS config into the client with the given parameters.
func LoadClientTLSConfigForInternalPort ¶
LoadClientTLSConfigForInternalPort loads tls config for connecting to internal ports of cluster
func LoadServerTLSConfig ¶
LoadServerTLSConfig loads the TLS config into the server with the given parameters.
func LoadServerTLSConfigForInternalPort ¶
LoadServerTLSConfigForInternalPort loads the TLS config for the internal ports of the cluster
func MaybeKeyToBytes ¶
func MaybeKeyToBytes(k interface{}) interface{}
MaybeKeyToBytes converts the x.Sensitive type into []byte if the type of interface really is x.Sensitive. We keep the type x.Sensitive for private and public keys so that it doesn't get printed into the logs but the type the JWT library needs is []byte.
func MetricsContext ¶
MetricsContext returns a context with tags that are useful for distinguishing the state of the running system. This context will be used to derive other contexts.
func MinioCredentialsProvider ¶
func MinioCredentialsProvider(scheme string, requestCreds credentials.Value) credentials.Provider
func MinioCredentialsProviderWithoutEnv ¶
func MinioCredentialsProviderWithoutEnv(requestCreds credentials.Value) credentials.Provider
func MonitorCacheHealth ¶
MonitorCacheHealth periodically monitors the cache metrics and reports if there is high contention in the cache.
func MonitorMemoryMetrics ¶
func NamespaceAttr ¶
NamespaceAttr is used to generate attr from namespace.
func NamespaceAttrList ¶
func NamespaceToBytes ¶
func NewBadgerCollector ¶
func NewBadgerCollector() prometheus.Collector
NewBadgerCollector returns a prometheus Collector for Badger metrics from expvar.
func PageRange ¶
PageRange returns start and end indices given pagination params. Note that n is the size of the input list.
func ParseAttrList ¶
func ParseCompression ¶
func ParseCompression(cStr string) (bo.CompressionType, int)
ParseCompression returns badger.compressionType and compression level given compression string of format compression-type:compression-level
func ParseNamespace ¶
ParseNamespace returns the namespace from the given value.
func ParseNamespaceAttr ¶
ParseNamespaceAttr returns the namespace and attr from the given value.
func ParseNamespaceBytes ¶
func ParseRequest ¶
func ParseRequest(w http.ResponseWriter, r *http.Request, data interface{}) bool
ParseRequest parses the body of the given request.
func PredicateLang ¶
PredicateLang extracts the language from a predicate (or facet) name. Returns the predicate and the language tag, if any.
func PredicatePrefix ¶
PredicatePrefix returns the prefix for all keys belonging to this predicate except schema key.
func PrefixesToMatches ¶
PrefixesToMatches converts the prefixes for subscription to a list of match.
func PrintMutationEdge ¶
func PrintMutationEdge(plist *pb.DirectedEdge, key ParsedKey, startTs uint64)
PrintMutationEdge prints all edges that are being inserted into badger
func PrintOracleDelta ¶
func PrintOracleDelta(delta *pb.OracleDelta)
PrintOracleDelta prints all delta proposals that are commited
func PrintRollup ¶
func PrintRollup(plist *pb.PostingList, parts map[uint64]*pb.PostingList, baseKey []byte, ts uint64)
PrintRollup prints information about any rollup that happen
func PrintVersion ¶
func PrintVersion()
PrintVersion prints version and other helpful information if --version.
func ProposalKey ¶
{2 bytes Node ID} {4 bytes for random} {2 bytes zero}
func QueryMaxOpenFiles ¶
func ReadGroupIdFile ¶
ReadGroupIdFile reads the file at the given path and attempts to retrieve the group ID stored in it.
func ReadLine ¶
ReadLine 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 RegisterAclAndEncFlags ¶
func RegisterClientTLSFlags ¶
RegisterClientTLSFlags registers the required flags to set up a TLS client.
func RegisterEncFlag ¶
func RegisterExporters ¶
RegisterExporters sets up the services to which metrics will be exported.
func RegisterServerTLSFlags ¶
RegisterServerTLSFlags registers the required flags to set up a TLS server.
func RemoveDuplicates ¶
RemoveDuplicates sorts the slice of strings and removes duplicates. changes the input slice. This function should be called like: someSlice = RemoveDuplicates(someSlice)
func Reply ¶
func Reply(w http.ResponseWriter, rep interface{})
Reply sets the body of an HTTP response to the JSON representation of the given reply.
func RetryUntilSuccess ¶
RetryUntilSuccess runs the given function until it succeeds or can no longer be retried.
func ReverseKey ¶
ReverseKey generates a reverse key with the given attribute and UID. The structure of a reverse key is as follows:
byte 0: key type prefix (set to DefaultPrefix or ByteSplit if part of a multi-part list) byte 1-2: length of attr next len(attr) bytes: value of attr next byte: data type prefix (set to ByteReverse) next eight bytes: value of uid next eight bytes (optional): if the key corresponds to a split list, the startUid of the split stored in this key.
func RunVlogGC ¶
RunVlogGC runs value log gc on store. It runs GC unconditionally after every 1 minute.
func SchemaKey ¶
SchemaKey returns schema key for given attribute. Schema keys are stored separately with unique prefix, since we need to iterate over all schema keys. The structure of a schema key is as follows:
byte 0: key type prefix (set to ByteSchema) byte 1-2: length of attr next len(attr) bytes: value of attr
func SetHttpStatus ¶
func SetHttpStatus(w http.ResponseWriter, code int, msg string)
SetHttpStatus is similar to SetStatus but sets a proper HTTP status code in the response instead of always returning HTTP 200 (OK).
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 ¶
func SetStatusWithData(w http.ResponseWriter, code, msg string)
SetStatusWithData sets the errors in the response and ensures that the data key in the data is present with value nil. 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 SetStatusWithErrors ¶
func SetStatusWithErrors(w http.ResponseWriter, code string, errs []string)
func SetupConnection ¶
func SetupConnection( host string, tlsCfg *tls.Config, useGz bool, dialOpts ...grpc.DialOption, ) (*grpc.ClientConn, error)
SetupConnection starts a secure gRPC connection to the given host.
func ShouldCrash ¶
ShouldCrash returns true if the error should cause the process to crash.
func SlashTLSConfig ¶
SlashTLSConfig returns the TLS config appropriate for SlashGraphQL This assumes that endpoint is not empty, and in the format "domain.grpc.cloud.dg.io:443"
func SpanTimer ¶
func SpanTimer(spanInterface interface{}, name string) func()
SpanTimer returns a function used to record the duration of the given span. It supports both OpenCensus and OpenTelemetry spans
func SplitKey ¶
SplitKey takes a key baseKey and generates the key of the list split that starts at startUid.
func StarAllPredicates ¶
StarAllPredicates returns the complete list of pre-defined predicates that needs to be expanded when * is given as a predicate.
func StartListenHttpAndHttps ¶
func TLSBaseConfig ¶
TLSBaseConfig returns a *tls.Config with the base set of security requirements (minimum TLS v1.2 and set of cipher suites)
func ToHex ¶
ToHex converts a uint64 to a hex byte array. If rdf is true it will use < > brackets to delimit the value. Otherwise it will use quotes like JSON requires.
func TypeKey ¶
TypeKey returns type key for given type name. Type keys are stored separately with a unique prefix, since we need to iterate over all type keys. The structure of a type key is as follows:
byte 0: key type prefix (set to ByteType) byte 1-2: length of typeName next len(attr) bytes: value of attr (the type name)
func UpdateDrainingMode ¶
func UpdateDrainingMode(enable bool)
UpdateDrainingMode updates the server's draining mode
func UpdateHealthStatus ¶
func UpdateHealthStatus(ok bool)
UpdateHealthStatus updates the server's health status so it can start accepting requests.
func ValidateAddress ¶
ValidateAddress checks whether given address can be used with grpc dial function
func VerifyPack ¶
func VerifyPack(plist *pb.PostingList)
VerifyPack works in debug mode. Check out the comment in debug_on.go
func VerifyPostingSplits ¶
func VerifyPostingSplits(kvs []*bpb.KV, plist *pb.PostingList, parts map[uint64]*pb.PostingList, baseKey []byte)
VerifyPostingSplits works in debug mode. Check out the comment in debug_on.go
func VerifySnapshot ¶
func VerifySnapshot(pstore *badger.DB, readTs uint64)
VerifySnapshot works in debug mode. Check out the comment in debug_on.go
func WalkPathFunc ¶
WalkPathFunc walks the directory 'dir' and collects all path names matched by func f. If the path is a directory, it will set the bool argument to true. Returns empty string slice if nothing found, otherwise returns all matched path names.
func WithAuthorizationCredentials ¶
func WithAuthorizationCredentials(authToken string) grpc.DialOption
WithAuthorizationCredentials adds Authorization: <api-token> to every GRPC request This is mostly used by Slash GraphQL to authenticate requests
func WithMethod ¶
WithMethod returns a new updated context with the tag KeyMethod set to the given value.
func WriteFileSync ¶
WriteFileSync is the same as bufio.WriteFile, but syncs the data before closing.
func WriteGroupIdFile ¶
WriteGroupIdFile writes the given group ID to the group_id file inside the given postings directory.
func WriteResponse ¶
WriteResponse writes response body, transparently compressing if necessary.
Types ¶
type BytesBuffer ¶
type BytesBuffer struct {
// contains filtered or unexported fields
}
BytesBuffer provides a buffer backed by byte slices.
func (*BytesBuffer) CopyTo ¶
func (b *BytesBuffer) CopyTo(o []byte) int
CopyTo copies the contents of the buffer to the given byte slice. Caller should ensure that o is of appropriate length.
func (*BytesBuffer) Length ¶
func (b *BytesBuffer) Length() int
Length returns the size of the buffer.
func (*BytesBuffer) Slice ¶
func (b *BytesBuffer) Slice(n int) []byte
Slice returns a slice of length n to be used for writing.
func (*BytesBuffer) TruncateBy ¶
func (b *BytesBuffer) TruncateBy(n int)
TruncateBy reduces the size of the bugger by the given amount. Always give back <= touched bytes.
type CloseFunc ¶
type CloseFunc func()
CloseFunc needs to be called to close all the client connections.
func GetDgraphClient ¶
GetDgraphClient creates a Dgraph client based on the following options in the configuration: --slash_grpc_endpoint specifies the grpc endpoint for slash. It takes precedence over --alpha and TLS --alpha specifies a comma separated list of endpoints to connect to --tls "ca-cert=; client-cert=; client-key=;" etc specify the TLS configuration of the connection --retries specifies how many times we should retry the connection to each endpoint upon failures --user and --password specify the credentials we should use to login with the server
type ExportedGQLSchema ¶
type GqlError ¶
type GqlError struct {
Message string `json:"message"`
Locations []Location `json:"locations,omitempty"`
Path []interface{} `json:"path,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}
GqlError is a GraphQL spec compliant error structure. See GraphQL spec on errors here: https://graphql.github.io/graphql-spec/June2018/#sec-Errors
Note: "Every error must contain an entry with the key message with a string description of the error intended for the developer as a guide to understand and correct the error."
"If an error can be associated to a particular point in the request [the error] should contain an entry with the key locations with a list of locations"
Path is about GraphQL results and Errors for GraphQL layer.
Extensions is for everything else.
func GqlErrorf ¶
GqlErrorf returns a new GqlError with the message and args Sprintf'ed as the GqlError's Message.
func (*GqlError) WithLocations ¶
WithLocations adds a list of locations to a GqlError and returns the same GqlError (fluent style).
type GqlErrorList ¶
type GqlErrorList []*GqlError
GqlErrorList is a list of GraphQL errors as would be found in a response.
func (GqlErrorList) Error ¶
func (errList GqlErrorList) Error() string
type Histogram ¶
A Histogram collects observed values by keeping bucketed counts. For convenience, pb.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 ¶
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 ¶
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 Keys ¶
type Keys struct {
AclJwtAlg jwt.SigningMethod
AclSecretKey interface{}
AclPublicKey interface{}
AclSecretKeyBytes Sensitive // we need this to compute hash for auth
AclAccessTtl time.Duration
AclRefreshTtl time.Duration
EncKey Sensitive
}
Keys holds the configuration for ACL and encryption.
type LimiterConf ¶
LimiterConf is the configuration options for LimiterConf.
type LogWriter ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func InitLogger ¶
func InitLogger(conf *LoggerConf, filename string) (*Logger, error)
type LoggerConf ¶
type MinioClient ¶
func NewMinioClient ¶
func NewMinioClient(uri *url.URL, creds *MinioCredentials) (*MinioClient, error)
func (*MinioClient) ParseBucketAndPrefix ¶
func (*MinioClient) ParseBucketAndPrefix(path string) (string, string)
ParseBucketAndPrefix returns the bucket and prefix given a path string
func (*MinioClient) ValidateBucket ¶
type MinioCredentials ¶
type MinioCredentials struct {
AccessKey string
SecretKey pb.Sensitive
SessionToken pb.Sensitive
Anonymous bool
}
MinioCredentials holds the credentials needed to perform a backup/export operation. If these credentials are missing the default credentials will be used.
type Options ¶
type Options struct {
// PortOffset will be used to determine the ports to use (port = default port + offset).
PortOffset int
// Limit options:
//
// query-edge uint64 - maximum number of edges that can be returned in a query
// normalize-node int - maximum number of nodes that can be returned in a query that uses the
// normalize directive
// mutations-nquad int - maximum number of nquads that can be inserted in a mutation request
// BlockDropAll bool - if set to true, the drop all operation will be rejected by the server.
// query-timeout duration - Maximum time after which a query execution will fail.
// max-retries int64 - maximum number of retries made by dgraph to commit a transaction to disk.
// shared-instance bool - if set to true, ACLs will be disabled for non-galaxy users.
Limit *z.SuperFlag
LimitMutationsNquad int
LimitQueryEdge uint64
BlockClusterWideDrop bool
LimitNormalizeNode int
QueryTimeout time.Duration
MaxRetries int64
// GraphQL options:
//
// extensions bool - Will be set to see extensions in GraphQL results
// debug bool - Will enable debug mode in GraphQL.
// lambda-url string - Stores the URL of lambda functions for custom GraphQL resolvers
// The configured lambda-url can have a parameter `$ns`,
// which should be replaced with the correct namespace value at runtime.
// ===========================================================================================
// | lambda-url | $ns | namespacedLambdaUrl |
// |==========================================|=====|========================================|
// | http://localhost:8686/graphql-worker/$ns | 1 | http://localhost:8686/graphql-worker/1 |
// | http://localhost:8686/graphql-worker | 1 | http://localhost:8686/graphql-worker |
// |=========================================================================================|
//
// poll-interval duration - The polling interval for graphql subscription.
GraphQL *z.SuperFlag
GraphQLDebug bool
// feature flags
NormalizeCompatibilityMode string
}
Options stores the options for this package.
var Config Options
Config stores the global instance of this package's options.
type ParsedKey ¶
type ParsedKey struct {
Attr string
Uid uint64
StartUid uint64
Term string
Count uint32
ByteType byte
HasStartUid bool
// contains filtered or unexported fields
}
ParsedKey represents a key that has been parsed into its multiple attributes.
func Parse ¶
Parse would parse the key. ParsedKey does not reuse the key slice, so the key slice can change without affecting the contents of ParsedKey.
func (ParsedKey) CountPrefix ¶
CountPrefix returns the prefix for count keys.
func (ParsedKey) DataPrefix ¶
DataPrefix returns the prefix for data keys.
func (ParsedKey) IndexPrefix ¶
IndexPrefix returns the prefix for index keys.
func (ParsedKey) IsCountOrCountRev ¶
IsCountOrCountRev returns whether the key is a count or a count rev key.
func (ParsedKey) IsCountRev ¶
IsCountRev returns whether the key is a count rev key.
func (ParsedKey) ReversePrefix ¶
ReversePrefix returns the prefix for index keys.
func (ParsedKey) SkipPredicate ¶
SkipPredicate returns the first key after the keys corresponding to the predicate of this key. Useful when iterating in the reverse order.
func (ParsedKey) ToBackupKey ¶
ToBackupKey returns the key in the format used for writing backups.
type QueryResWithData ¶
type QueryResWithData struct {
Errors GqlErrorList `json:"errors"`
Data *string `json:"data"`
}
QueryResWithData represents a response that holds errors as well as data.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements a basic rate limiter.
func NewRateLimiter ¶
NewRateLimiter creates a rate limiter that limits lease by maxTokens in an interval specified by refillAfter.
func (*RateLimiter) Allow ¶
func (r *RateLimiter) Allow(ns uint64, req int64) bool
Allow checks if the request for req number of tokens can be allowed for a given namespace. If request is allowed, it subtracts the req from the available tokens.
func (*RateLimiter) RefillPeriodically ¶
func (r *RateLimiter) RefillPeriodically()
RefillPeriodically refills the tokens of all the namespaces to maxTokens periodically .
type SafeMutex ¶
type SafeMutex struct {
// contains filtered or unexported fields
}
SafeMutex can be used in place of sync.RWMutex. It allows code to assert whether the mutex is locked.
func (*SafeMutex) AlreadyLocked ¶
AlreadyLocked returns true if safe mutex is already being held.
func (*SafeMutex) AssertLock ¶
func (s *SafeMutex) AssertLock()
AssertLock asserts whether the lock is being held.
func (*SafeMutex) AssertRLock ¶
func (s *SafeMutex) AssertRLock()
AssertRLock asserts whether the reader lock is being held.
type Sensitive ¶
type Sensitive []byte
Sensitive implements the Stringer interface to redact its contents. Use this type for sensitive info such as keys, passwords, or secrets so it doesn't leak as output such as logs.
type Stopper ¶
type Stopper interface {
Stop()
}
Stopper is an interface tasked with stopping the profiling process.
func StartProfile ¶
StartProfile starts a new mode for profiling.
type SubCommand ¶
SubCommand a represents a sub-command in the command-line interface.
type TLSHelperConfig ¶
type TLSHelperConfig struct {
CertRequired bool
Cert string
Key string
ServerName string
RootCACert string
ClientAuth string
UseSystemCACerts bool
}
TLSHelperConfig define params used to create a tls.Config
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer implements a timer that supports recording the duration of events.
type ValueTypeInfo ¶
type ValueTypeInfo int32
ValueTypeInfo represents information about the type of values in DirectedEdge/Posting/N-Quad.
const ( // ValueUnknown represents an unknown type of value. ValueUnknown ValueTypeInfo = iota // ValueEmpty represents a value with no UID and no value. ValueEmpty // ValueUid represents a value with an UID. ValueUid // ValuePlain represents a plain old value without defined language tag. ValuePlain // ValueMulti represents a value which is part of a multi-value posting list (like language). ValueMulti )
Type of a data inside DirectedEdge, Posting or N-Quad
func ValueType ¶
func ValueType(hasValue, hasLang, hasSpecialId bool) ValueTypeInfo
ValueType s a helper function to decide value type of DirectedEdge/Posting/N-Quad.
type WorkerOptions ¶
type WorkerOptions struct {
// TmpDir is a directory to store temporary buffers.
TmpDir string
// ExportPath indicates the folder to which exported data will be saved.
ExportPath string
// Trace options:
//
// ratio float64 - the ratio of queries to trace (must be between 0 and 1)
// jaeger string - URL of Jaeger to send OpenCensus traces
// datadog string - URL of Datadog to send OpenCensus traces
Trace *z.SuperFlag
// MyAddr stores the address and port for this alpha.
MyAddr string
// ZeroAddr stores the list of address:port for the zero instances associated with this alpha.
// Alpha would communicate via only one zero address from the list. All
// the other addresses serve as fallback.
ZeroAddr []string
// TLS client config which will be used to connect with zero and alpha internally
TLSClientConfig *tls.Config
// TLS server config which will be used to initiate server internal port
TLSServerConfig *tls.Config
// Raft stores options related to Raft.
Raft *z.SuperFlag
// Badger stores the badger options.
Badger badger.Options
// WhiteListedIPRanges is a list of IP ranges from which requests will be allowed.
WhiteListedIPRanges []IPRange
// StrictMutations will cause mutations to unknown predicates to fail if set to true.
StrictMutations bool
// AclEnabled indicates whether the ACL feature is turned on.
AclEnabled bool
// AclJwtAlg stores the JWT signing algorithm.
AclJwtAlg jwt.SigningMethod
// AclPublicKey stores the public key used to verify JSON Web Tokens (JWT).
// It could be a either a RSA or ECDSA PublicKey or HMAC symmetric key.
// depending upon the JWT signing algorithm. Note that for symmetric algorithms,
// this will contain the same key as the private key, needs to be used carefully.
AclPublicKey interface{}
// AbortOlderThan tells Dgraph to discard transactions that are older than this duration.
AbortOlderThan time.Duration
// ProposedGroupId will be used if there's a file in the p directory called group_id with the
// proposed group ID for this server.
ProposedGroupId uint32
// StartTime is the start time of the alpha
StartTime time.Time
// Security options:
//
// whitelist string - comma separated IP addresses
// token string - if set, all Admin requests to Dgraph will have this token.
Security *z.SuperFlag
// EncryptionKey is the key used for encryption at rest, backups, exports.
EncryptionKey Sensitive
// LogDQLRequest indicates whether alpha should log all query/mutation requests coming to it.
// Ideally LogDQLRequest should be a bool value. But we are reading it using atomics across
// queries hence it has been kept as int32. LogDQLRequest value 1 enables logging of requests
// coming to alphas and 0 disables it.
LogDQLRequest int32
// If true, we should call msync or fsync after every write to survive hard reboots.
HardSync bool
// Audit contains the audit flags that enables the audit.
Audit bool
}
WorkerOptions stores the options for the worker package. It's declared here since it's used by multiple packages.
var WorkerConfig WorkerOptions
WorkerConfig stores the global instance of the worker package's options.
func (*WorkerOptions) Parse ¶
func (w *WorkerOptions) Parse(conf *viper.Viper)