mirror of
https://github.com/hanzoai/graph.git
synced 2026-10-30 18:35:37 +00:00
Derived from Dgraph (github.com/dgraph-io/dgraph) at commit 64804bd2, Apache-2.0. See NOTICE. WHAT THIS IS. The graph engine as a Go library: posting lists, the DQL parser, the type and tokenizer system, the index and schema layers, and the wire types. 39,170 lines of the upstream's 166,337. THE STORE is github.com/luxfi/zapdb, a Badger fork that kept the package name, the subpackages (options, pb, y) and the API — Open, OpenManaged, DB, Options — so the 74 import sites are aliased rather than rewritten. THE CODEC is ZAP. zapdb serializes with ZAP, not protobuf: its pb package builds the ZAP types by default and the protobuf ones only under `-tags grpc`, a path that does not compile (table/builder.go calls pb.Marshal, which that tag removes). One call site in posting needed converting; every other type here is Hanzo's own protobuf and is untouched. NO TRANSPORT. An embedded engine dials nothing, so nothing here imports google.golang.org/grpc. Removed: 20 transport functions in x, the generated service stubs for Raft, Zero and Worker (1,657 lines), and the JWT helper — identity belongs to IAM. The core called none of them. NOT KEPT: worker, conn, raftwal, the cluster commands, the GraphQL layer and the test harnesses. `query`, the DQL execution engine, went with them because it depends on worker; parsing DQL is available here, executing it is not. The history of the upstream project lives at github.com/dgraph-io/dgraph. This repository begins at the derivation because three quarters of that history describes code this fork does not carry.
167 lines
7.1 KiB
Go
167 lines
7.1 KiB
Go
/*
|
|
* SPDX-FileCopyrightText: © 2017-2026 Istari Digital, Inc.
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
package x
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"fmt"
|
|
"net"
|
|
"time"
|
|
|
|
"github.com/golang-jwt/jwt/v5"
|
|
"github.com/spf13/viper"
|
|
|
|
badger "github.com/luxfi/zapdb"
|
|
"github.com/dgraph-io/ristretto/v2/z"
|
|
)
|
|
|
|
// Options stores the options for this package.
|
|
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
|
|
}
|
|
|
|
// Config stores the global instance of this package's options.
|
|
var Config Options
|
|
|
|
// IPRange represents an IP range.
|
|
type IPRange struct {
|
|
Lower, Upper net.IP
|
|
}
|
|
|
|
// WorkerOptions stores the options for the worker package. It's declared here
|
|
// since it's used by multiple packages. Note the String override for this type,
|
|
// added to prevent sensitive information from being logged.
|
|
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
|
|
// SlowQueryLogThreshold is the duration after which a query is considered slow and logged
|
|
// with structured fields including trace ID. Zero disables slow query logging.
|
|
SlowQueryLogThreshold time.Duration
|
|
// 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
|
|
}
|
|
|
|
// WorkerConfig stores the global instance of the worker package's options.
|
|
var WorkerConfig WorkerOptions
|
|
|
|
func (w *WorkerOptions) Parse(conf *viper.Viper) {
|
|
w.MyAddr = conf.GetString("my")
|
|
w.Trace = z.NewSuperFlag(conf.GetString("trace")).MergeAndCheckDefault(TraceDefaults)
|
|
|
|
survive := conf.GetString("survive")
|
|
AssertTruef(survive == "process" || survive == "filesystem",
|
|
"Invalid survival mode: %s", survive)
|
|
w.HardSync = survive == "filesystem"
|
|
}
|
|
|
|
// String implements the Stringer interface to redact sensitive fields when logging.
|
|
func (w WorkerOptions) String() string {
|
|
return fmt.Sprintf("{TmpDir:%s ExportPath:%s MyAddr:%s ZeroAddr:%v Raft:%v "+
|
|
"WhiteListedIPRanges:%v StrictMutations:%v AclEnabled:%v AclJwtAlg:%v "+
|
|
"AclPublicKey:**** AbortOlderThan:%v ProposedGroupId:%d StartTime:%v "+
|
|
"Security:**** EncryptionKey:**** LogDQLRequest:%d SlowQueryThreshold:%v HardSync:%v Audit:%v}",
|
|
w.TmpDir, w.ExportPath, w.MyAddr, w.ZeroAddr, w.Raft,
|
|
w.WhiteListedIPRanges, w.StrictMutations, w.AclEnabled, w.AclJwtAlg,
|
|
w.AbortOlderThan, w.ProposedGroupId, w.StartTime,
|
|
w.LogDQLRequest, w.SlowQueryLogThreshold, w.HardSync, w.Audit)
|
|
}
|