x

package
v25.0.0-custom-qt-impr... Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: Apache-2.0 Imports: 86 Imported by: 2

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 (
	TraceDefaults     = `ratio=0.01; jaeger=; datadog=;`
	TelemetryDefaults = `reports=true;sentry=false;`
)
View Source
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 = "-"
)
View Source
const (

	//  old logs before https://github.com/hypermodeinc/dgraph/pull/8323 contain deprecated verification text in header
	VerificationTextDeprecated = "Hello World"
	VerificationText           = "dlroW olloH"
)
View Source
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=;`
)
View Source
const (
	// Success is equivalent to the HTTP 200 error code.
	Success = "Success"
	// ErrorUnauthorized is equivalent to the HTTP 401 error code.
	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

View Source
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"
)
View Source
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, "")
)
View Source
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.

View Source
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{}
)
View Source
var ErrMissingDir = errors.Errorf("missing or empty directory")

ErrMissingDir is thrown by IsMissingOrEmptyDir if the given path is a missing or empty directory.

View Source
var NonRootTemplate string = `` /* 653-byte string literal not displayed */

NonRootTemplate defines the help template for dgraph sub-command.

View Source
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.

View Source
var (
	// ServerCloser is used to signal and wait for other goroutines to return gracefully after user
	// requests shutdown.
	ServerCloser = z.NewCloser(0)
)
View Source
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

func AskUserPassword(userid string, pwdType string, times int) (string, error)

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

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

AssertTruef is AssertTrue with extra info.

func AssertTruefNoTrace

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

AssertTruefNoTrace is AssertTruef without a stack trace.

func AttachAccessJwt

func AttachAccessJwt(ctx context.Context, r *http.Request) context.Context

AttachAccessJwt adds any incoming JWT header data into the grpc context metadata

func AttachAuthToken

func AttachAuthToken(ctx context.Context, r *http.Request) context.Context

AttachAuthToken adds any incoming PoorMan's auth header data into the grpc context metadata

func AttachJWTNamespace

func AttachJWTNamespace(ctx context.Context) context.Context

AttachJWTNamespace attaches the namespace in the JWT claims to the context if present, otherwise it attaches the galaxy namespace.

func AttachJWTNamespaceOutgoing

func AttachJWTNamespaceOutgoing(ctx context.Context) (context.Context, error)

AttachJWTNamespaceOutgoing attaches the namespace in the JWT claims to the outgoing metadata of the context.

func AttachNamespace

func AttachNamespace(ctx context.Context, namespace uint64) context.Context

AttachNamespace adds given namespace to the metadata of the context.

func AttachNamespaceOutgoing

func AttachNamespaceOutgoing(ctx context.Context, namespace uint64) context.Context

AttachNamespaceOutgoing adds given namespace in the outgoing metadata of the context.

func AttachRemoteIP

func AttachRemoteIP(ctx context.Context, r *http.Request) context.Context

AttachRemoteIP adds any incoming IP data into the grpc context metadata

func AttachRootNsOperation

func AttachRootNsOperation(ctx context.Context, ns uint64) context.Context

AttachRootNsOperation specifies in the context that it will be used for doing a Root Namespace operation.

func AttrFrom2103

func AttrFrom2103(attr string) (string, error)

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 AttrInRootNamespace(attr string) string

func BuildDetails

func BuildDetails() string

BuildDetails returns a string containing details about the Dgraph binary.

func BuildEncFlag

func BuildEncFlag(filename string) string

func Check

func Check(err error)

Check logs fatal if err != nil.

func Check2

func Check2(_ interface{}, err error)

Check2 acts as convenience wrapper around Check, using the 2nd argument as error.

func Checkf

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

Checkf is Check with extra info.

func CheckfNoLog

func CheckfNoLog(err error)

CheckfNoLog exits on error without any message (to avoid duplicate error messages).

func CheckfNoTrace

func CheckfNoTrace(err error)

CheckfNoTrace is Checkf without a stack trace.

func Codename

func Codename() string

Codename returns a string containing the dgraphCodename.

func CountKey

func CountKey(attr string, count uint32, reverse bool) []byte

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

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

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

func DataPrefix(ns uint64) []byte

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

func DeepCopyJsonMap(m map[string]interface{}) map[string]interface{}

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.

  1. v2.0.0-rc1-127-gd20a768b3 => dev version
  2. v2.0.0 => prod version

func Diff

func Diff(dst map[string]struct{}, src map[string]struct{}) ([]string, []string)

Diff computes the difference between the keys of the two given maps.

func DivideAndRule

func DivideAndRule(num int) (numGo, width int)

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

func ExponentialRetry(maxRetries int, waitAfterFailure time.Duration,
	f func() error) error

ExponentialRetry runs the given function until it succeeds or can no longer be retried.

func ExtractJwt

func ExtractJwt(ctx context.Context) (string, error)

func ExtractNamespace

func ExtractNamespace(ctx context.Context) (uint64, error)

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 ExtractNamespaceFrom

func ExtractNamespaceFrom(ctx context.Context) (uint64, error)

func ExtractNamespaceFromJwt

func ExtractNamespaceFromJwt(jwtToken string) (uint64, error)

func ExtractNamespaceHTTP

func ExtractNamespaceHTTP(r *http.Request) uint64

ExtractNamespaceHTTP parses the namespace value from the incoming HTTP request.

func ExtractUserName

func ExtractUserName(jwtToken string) (string, error)

func Fatalf

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

Fatalf logs fatal.

func FillCommonFlags

func FillCommonFlags(flag *pflag.FlagSet)

FillCommonFlags stores flags common to Alpha and Zero.

func FindDataFiles

func FindDataFiles(str string, ext []string) []string

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

func FindFilesFunc(dir string, f func(string) bool) []string

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

func FixedDuration(d time.Duration) string

FixedDuration returns the given duration as a string of fixed length.

func FromBackupKey

func FromBackupKey(backupKey *pb.BackupKey) []byte

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

func GetCachePercentages(cpString string, numExpected int) ([]int64, error)

GetCachePercentages returns the slice of cache percentages given the "," (comma) separated cache percentages(integers) string and expected number of caches.

func GetForceNamespace

func GetForceNamespace(ctx context.Context) string

func GetPassAndLogin

func GetPassAndLogin(dg *dgo.Dgraph, opt *CredOpt) error

GetPassAndLogin uses the given credentials and client to perform the login operation.

func GetRandomName

func GetRandomName(retry int) string

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 HasString

func HasString(a []string, b string) bool

HasString returns whether the slice contains the given string.

func HasWhitelistedIP

func HasWhitelistedIP(ctx context.Context) (net.Addr, error)

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

func IndexKey(attr, term string) []byte

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

func IsAclPredicate(pred string) bool

IsAclPredicate returns true if the predicate is in the list of reserved predicates for the ACL feature.

func IsDropOpKey

func IsDropOpKey(key []byte) (bool, error)

func IsGqlErrorList

func IsGqlErrorList(err error) bool

IsGqlErrorList tells whether the given err is a list of GraphQL errors.

func IsInternalPredicate

func IsInternalPredicate(pred string) bool

IsInternalPredicate returns true if the predicate is in the internal predicate list. Currently, `uid` is the only such candidate.

func IsJwtExpired

func IsJwtExpired(err error) bool

IsJwtExpired returns true if the error indicates that the jwt has expired.

func IsMissingOrEmptyDir

func IsMissingOrEmptyDir(path string) (err error)

IsMissingOrEmptyDir returns true if the path either does not exist or is a directory that is empty.

func IsOtherReservedPredicate

func IsOtherReservedPredicate(pred string) bool

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

func IsPreDefinedPredicate(pred string) bool

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

func IsPreDefinedType(typ string) bool

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

func IsReservedPredicate(pred string) bool

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:

  1. dgraph.type (reserved = true, pre_defined = true )
  2. dgraph.blah (reserved = true, pre_defined = false)
  3. person.name (reserved = false, pre_defined = false)

func IsReservedType

func IsReservedType(typ string) bool

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 IsReverseAttr(attr string) bool

func IsRootNsOperation

func IsRootNsOperation(ctx context.Context) bool

func IsSuperAdmin

func IsSuperAdmin(groups []string) bool

func JemallocHandler

func JemallocHandler(w http.ResponseWriter, r *http.Request)

func KvWithMaxVersion

func KvWithMaxVersion(kvs *badgerpb.KVList, prefixes [][]byte) *badgerpb.KV

KvWithMaxVersion returns a KV with the max version from the list of KVs.

func LambdaUrl

func LambdaUrl(ns uint64) string

LambdaUrl returns the correct lambda-url for the given namespace

func LoadClientTLSConfig

func LoadClientTLSConfig(v *viper.Viper) (*tls.Config, error)

LoadClientTLSConfig loads the TLS config into the client with the given parameters.

func LoadClientTLSConfigForInternalPort

func LoadClientTLSConfigForInternalPort(v *viper.Viper) (*tls.Config, error)

LoadClientTLSConfigForInternalPort loads tls config for connecting to internal ports of cluster

func LoadServerTLSConfig

func LoadServerTLSConfig(v *viper.Viper) (*tls.Config, error)

LoadServerTLSConfig loads the TLS config into the server with the given parameters.

func LoadServerTLSConfigForInternalPort

func LoadServerTLSConfigForInternalPort(v *viper.Viper) (*tls.Config, error)

LoadServerTLSConfigForInternalPort loads the TLS config for the internal ports of the cluster

func Log

func Log(err error, msg string)

func MarshalToSizedBuffer

func MarshalToSizedBuffer(buf []byte, m proto.Message) ([]byte, error)

func Max

func Max(a, b uint64) uint64

Max returns the maximum of the two given numbers.

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

func MetricsContext() context.Context

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 Min

func Min(a, b uint64) uint64

Min returns the minimum of the two given numbers.

func MinioCredentialsProvider

func MinioCredentialsProvider(scheme string, requestCreds credentials.Value) credentials.Provider

func MinioCredentialsProviderWithoutEnv

func MinioCredentialsProviderWithoutEnv(requestCreds credentials.Value) credentials.Provider

func MonitorCacheHealth

func MonitorCacheHealth(db *badger.DB, closer *z.Closer)

MonitorCacheHealth periodically monitors the cache metrics and reports if there is high contention in the cache.

func MonitorDiskMetrics

func MonitorDiskMetrics(dirTag string, dir string, lc *z.Closer)

func MonitorMemoryMetrics

func MonitorMemoryMetrics(lc *z.Closer)

func NamespaceAttr

func NamespaceAttr(ns uint64, attr string) string

NamespaceAttr is used to generate attr from namespace.

func NamespaceAttrList

func NamespaceAttrList(ns uint64, preds []string) []string

func NamespaceToBytes

func NamespaceToBytes(ns uint64) []byte

func NewBadgerCollector

func NewBadgerCollector() prometheus.Collector

NewBadgerCollector returns a prometheus Collector for Badger metrics from expvar.

func PageRange

func PageRange(count, offset, n int) (int, int)

PageRange returns start and end indices given pagination params. Note that n is the size of the input list.

func Panic

func Panic(err error)

Panic on error.

func ParseAttr

func ParseAttr(attr string) string

ParseAttr returns the attr from the given value.

func ParseAttrList

func ParseAttrList(attrs []string) []string

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 ParseJWT

func ParseJWT(jwtStr string) (jwt.MapClaims, error)

func ParseNamespace

func ParseNamespace(attr string) uint64

ParseNamespace returns the namespace from the given value.

func ParseNamespaceAttr

func ParseNamespaceAttr(attr string) (uint64, string)

ParseNamespaceAttr returns the namespace and attr from the given value.

func ParseNamespaceBytes

func ParseNamespaceBytes(attr string) ([]byte, string)

func ParseRequest

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

ParseRequest parses the body of the given request.

func PredicateLang

func PredicateLang(s string) (string, string)

PredicateLang extracts the language from a predicate (or facet) name. Returns the predicate and the language tag, if any.

func PredicatePrefix

func PredicatePrefix(predicate string) []byte

PredicatePrefix returns the prefix for all keys belonging to this predicate except schema key.

func PrefixesToMatches

func PrefixesToMatches(prefixes [][]byte, ignore string) []*badgerpb.Match

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

func ProposalKey(id uint64) (uint64, error)

{2 bytes Node ID} {4 bytes for random} {2 bytes zero}

func QueryMaxOpenFiles

func QueryMaxOpenFiles() (int, error)

func ReadGroupIdFile

func ReadGroupIdFile(pdir string) (uint32, error)

ReadGroupIdFile reads the file at the given path and attempts to retrieve the group ID stored in it.

func ReadLine

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

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 RegisterAclAndEncFlags(flag *pflag.FlagSet)

func RegisterClientTLSFlags

func RegisterClientTLSFlags(flag *pflag.FlagSet)

RegisterClientTLSFlags registers the required flags to set up a TLS client.

func RegisterEncFlag

func RegisterEncFlag(flag *pflag.FlagSet)

func RegisterExporters

func RegisterExporters(conf *viper.Viper, service string)

RegisterExporters sets up the services to which metrics will be exported.

func RegisterServerTLSFlags

func RegisterServerTLSFlags(flag *pflag.FlagSet)

RegisterServerTLSFlags registers the required flags to set up a TLS server.

func RemoveDuplicates

func RemoveDuplicates(s []string) (out []string)

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

func RetryUntilSuccess(maxRetries int, waitAfterFailure time.Duration,
	f func() error) error

RetryUntilSuccess runs the given function until it succeeds or can no longer be retried.

func ReverseKey

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

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

func RunVlogGC(store *badger.DB, closer *z.Closer)

RunVlogGC runs value log gc on store. It runs GC unconditionally after every 1 minute.

func SchemaKey

func SchemaKey(attr string) []byte

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 SchemaPrefix

func SchemaPrefix() []byte

SchemaPrefix returns the prefix for Schema keys.

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

func ShouldCrash(err error) bool

ShouldCrash returns true if the error should cause the process to crash.

func SinceMs

func SinceMs(startTime time.Time) float64

SinceMs returns the time since startTime in milliseconds (as a float).

func SlashTLSConfig

func SlashTLSConfig(endpoint string) (*tls.Config, error)

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

func SplitKey(baseKey []byte, startUid uint64) ([]byte, error)

SplitKey takes a key baseKey and generates the key of the list split that starts at startUid.

func StarAllPredicates

func StarAllPredicates(namespace uint64) []string

StarAllPredicates returns the complete list of pre-defined predicates that needs to be expanded when * is given as a predicate.

func StartListenHttpAndHttps

func StartListenHttpAndHttps(l net.Listener, tlsCfg *tls.Config, closer *z.Closer)

func StoreSync

func StoreSync(db DB, closer *z.Closer)

func TLSBaseConfig

func TLSBaseConfig() *tls.Config

TLSBaseConfig returns a *tls.Config with the base set of security requirements (minimum TLS v1.2 and set of cipher suites)

func ToHex

func ToHex(i uint64, rdf bool) []byte

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

func TypeKey(attr string) []byte

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 TypePrefix

func TypePrefix() []byte

TypePrefix returns the prefix for Schema keys.

func Unique

func Unique(a []string) []string

Unique takes an array and returns it with no duplicate entries.

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

func ValidateAddress(addr string) error

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 Version

func Version() string

Version returns a string containing the dgraphVersion.

func WalkPathFunc

func WalkPathFunc(dir string, f func(string, bool) bool) []string

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

func WithMethod(parent context.Context, method string) context.Context

WithMethod returns a new updated context with the tag KeyMethod set to the given value.

func WriteFileSync

func WriteFileSync(filename string, data []byte, perm os.FileMode) error

WriteFileSync is the same as bufio.WriteFile, but syncs the data before closing.

func WriteGroupIdFile

func WriteGroupIdFile(pdir string, group_id uint32) error

WriteGroupIdFile writes the given group ID to the group_id file inside the given postings directory.

func WriteResponse

func WriteResponse(w http.ResponseWriter, r *http.Request, b []byte) (int, error)

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

func GetDgraphClient(conf *viper.Viper, login bool) (*dgo.Dgraph, CloseFunc)

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 CredOpt

type CredOpt struct {
	UserID    string
	Password  string
	Namespace uint64
}

CredOpt stores the options for logging in, including the password and user.

type DB

type DB interface {
	Sync() error
}

type ExportedGQLSchema

type ExportedGQLSchema struct {
	Namespace uint64
	Schema    string
}

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

func GqlErrorf(message string, args ...interface{}) *GqlError

GqlErrorf returns a new GqlError with the message and args Sprintf'ed as the GqlError's Message.

func (*GqlError) Error

func (gqlErr *GqlError) Error() string

func (*GqlError) WithLocations

func (gqlErr *GqlError) WithLocations(locs ...Location) *GqlError

WithLocations adds a list of locations to a GqlError and returns the same GqlError (fluent style).

func (*GqlError) WithPath

func (gqlErr *GqlError) WithPath(path []interface{}) *GqlError

WithPath adds a path 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

type Histogram struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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

func NewHistogram(duration time.Duration, maxVal int64, sigFigs int) *Histogram

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

func (h *Histogram) RecordValue(v int64)

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 IPRange

type IPRange struct {
	Lower, Upper net.IP
}

IPRange represents an IP range.

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.

func GetEncAclKeys

func GetEncAclKeys(config *viper.Viper) (*Keys, error)

GetEncAclKeys returns the ACL and encryption keys as configured by the user through the --acl, --encryption, and --vault flags.

type LimiterConf

type LimiterConf struct {
	UidLeaseLimit uint64
	RefillAfter   time.Duration
}

LimiterConf is the configuration options for LimiterConf.

type Location

type Location struct {
	Line   int `json:"line,omitempty"`
	Column int `json:"column,omitempty"`
}

A Location is the Line+Column index of an error in a request.

type LogWriter

type LogWriter struct {
	FilePath      string
	MaxSize       int64
	MaxAge        int64 // number of days
	Compress      bool
	EncryptionKey []byte
	// contains filtered or unexported fields
}

func (*LogWriter) Close

func (l *LogWriter) Close() error

func (*LogWriter) Init

func (l *LogWriter) Init() (*LogWriter, error)

func (*LogWriter) Write

func (l *LogWriter) Write(p []byte) (int, error)

type Logger

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

func InitLogger

func InitLogger(conf *LoggerConf, filename string) (*Logger, error)

func (*Logger) AuditE

func (l *Logger) AuditE(msg string, args ...interface{})

func (*Logger) AuditI

func (l *Logger) AuditI(msg string, args ...interface{})

AuditI logs audit message as info. args are key value pairs with key as string value

func (*Logger) Sync

func (l *Logger) Sync()

type LoggerConf

type LoggerConf struct {
	Compress      bool
	Output        string
	EncryptionKey Sensitive
	Size          int64
	Days          int64
	MessageKey    string
}

type MinioClient

type MinioClient struct {
	*minio.Client
}

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

func (mc *MinioClient) ValidateBucket(uri *url.URL) (string, string, error)

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

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

func Parse(key []byte) (ParsedKey, error)

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

func (p ParsedKey) CountPrefix(reverse bool) []byte

CountPrefix returns the prefix for count keys.

func (ParsedKey) DataPrefix

func (p ParsedKey) DataPrefix() []byte

DataPrefix returns the prefix for data keys.

func (ParsedKey) IndexPrefix

func (p ParsedKey) IndexPrefix() []byte

IndexPrefix returns the prefix for index keys.

func (ParsedKey) IsCount

func (p ParsedKey) IsCount() bool

IsCount returns whether the key is a count key.

func (ParsedKey) IsCountOrCountRev

func (p ParsedKey) IsCountOrCountRev() bool

IsCountOrCountRev returns whether the key is a count or a count rev key.

func (ParsedKey) IsCountRev

func (p ParsedKey) IsCountRev() bool

IsCountRev returns whether the key is a count rev key.

func (ParsedKey) IsData

func (p ParsedKey) IsData() bool

IsData returns whether the key is a data key.

func (ParsedKey) IsIndex

func (p ParsedKey) IsIndex() bool

IsIndex returns whether the key is an index key.

func (ParsedKey) IsOfType

func (p ParsedKey) IsOfType(typ byte) bool

IsOfType checks whether the key is of the given type.

func (ParsedKey) IsReverse

func (p ParsedKey) IsReverse() bool

IsReverse returns whether the key is a reverse key.

func (ParsedKey) IsSchema

func (p ParsedKey) IsSchema() bool

IsSchema returns whether the key is a schema key.

func (ParsedKey) IsType

func (p ParsedKey) IsType() bool

IsType returns whether the key is a type key.

func (ParsedKey) ReversePrefix

func (p ParsedKey) ReversePrefix() []byte

ReversePrefix returns the prefix for index keys.

func (ParsedKey) SkipPredicate

func (p ParsedKey) SkipPredicate() []byte

SkipPredicate returns the first key after the keys corresponding to the predicate of this key. Useful when iterating in the reverse order.

func (ParsedKey) String

func (p ParsedKey) String() string

func (ParsedKey) ToBackupKey

func (p ParsedKey) ToBackupKey() *pb.BackupKey

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

func NewRateLimiter(maxTokens int64, refillAfter time.Duration, closer *z.Closer) *RateLimiter

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

func (s *SafeMutex) AlreadyLocked() bool

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.

func (*SafeMutex) Lock

func (s *SafeMutex) Lock()

Lock locks the safe mutex.

func (*SafeMutex) RLock

func (s *SafeMutex) RLock()

RLock holds the reader lock.

func (*SafeMutex) RUnlock

func (s *SafeMutex) RUnlock()

RUnlock releases the reader lock.

func (*SafeMutex) Unlock

func (s *SafeMutex) Unlock()

Unlock unlocks the safe mutex.

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.

func (Sensitive) String

func (Sensitive) String() string

type Stopper

type Stopper interface {
	Stop()
}

Stopper is an interface tasked with stopping the profiling process.

func StartProfile

func StartProfile(conf *viper.Viper) Stopper

StartProfile starts a new mode for profiling.

type SubCommand

type SubCommand struct {
	Cmd  *cobra.Command
	Conf *viper.Viper

	EnvPrefix string
}

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.

func (*Timer) Record

func (t *Timer) Record(name string)

Record records an event and assigns it the given name.

func (*Timer) Start

func (t *Timer) Start()

Start starts the timer and clears the list of records.

func (*Timer) String

func (t *Timer) String() string

func (*Timer) Total

func (t *Timer) Total() time.Duration

Total returns the duration since the timer was started.

type ToGlog

type ToGlog struct{}

ToGlog is a logger that forwards the output to glog.

func (*ToGlog) Debug

func (rl *ToGlog) Debug(v ...interface{})

func (*ToGlog) Debugf

func (rl *ToGlog) Debugf(format string, v ...interface{})

func (*ToGlog) Error

func (rl *ToGlog) Error(v ...interface{})

func (*ToGlog) Errorf

func (rl *ToGlog) Errorf(format string, v ...interface{})

func (*ToGlog) Fatal

func (rl *ToGlog) Fatal(v ...interface{})

func (*ToGlog) Fatalf

func (rl *ToGlog) Fatalf(format string, v ...interface{})

func (*ToGlog) Info

func (rl *ToGlog) Info(v ...interface{})

func (*ToGlog) Infof

func (rl *ToGlog) Infof(format string, v ...interface{})

func (*ToGlog) Panic

func (rl *ToGlog) Panic(v ...interface{})

func (*ToGlog) Panicf

func (rl *ToGlog) Panicf(format string, v ...interface{})

func (*ToGlog) Warning

func (rl *ToGlog) Warning(v ...interface{})

func (*ToGlog) Warningf

func (rl *ToGlog) Warningf(format string, v ...interface{})

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)

Jump to

Keyboard shortcuts

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