Files
zeekay f5aaeb712e Hanzo Graph — the engine, on zapdb, ZAP-native
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.
2026-08-20 21:26:27 -07:00

117 lines
2.7 KiB
Go

/*
* SPDX-FileCopyrightText: © 2017-2026 Istari Digital, Inc.
* SPDX-License-Identifier: Apache-2.0
*/
package x
import (
"crypto/sha256"
"fmt"
"io"
"os"
"regexp"
"runtime"
"github.com/golang/glog"
"github.com/dgraph-io/ristretto/v2/z"
)
var (
// These variables are set using -ldflags
dgraphVersion string
dgraphCodename string
gitBranch string
lastCommitSHA string
lastCommitTime string
)
func init() {
// check if any version is set by ldflags. If not so, it should be set as "dev"
if dgraphVersion == "" {
dgraphVersion = "dev"
}
}
// BuildDetails returns a string containing details about the Dgraph binary.
func BuildDetails() string {
licenseInfo := `Licensed under the Apache Public License 2.0`
buf := z.CallocNoRef(1, "X.BuildDetails")
jem := len(buf) > 0
z.Free(buf)
return fmt.Sprintf(`
Dgraph version : %v
Dgraph codename : %v
Dgraph SHA-256 : %x
Commit SHA-1 : %v
Commit timestamp : %v
Branch : %v
Go version : %v
jemalloc enabled : %v
GOMAXPROCS : %v
Num CPUs : %v
For Dgraph official documentation, visit https://docs.dgraph.io
For discussions about Dgraph , visit https://github.com/orgs/dgraph-io/discussions
%s.
© Istari Digital, Inc.
`,
dgraphVersion, dgraphCodename, ExecutableChecksum(), lastCommitSHA, lastCommitTime, gitBranch,
runtime.Version(), jem, runtime.GOMAXPROCS(0), runtime.NumCPU(), licenseInfo)
}
// PrintVersion prints version and other helpful information if --version.
func PrintVersion() {
glog.Infof("\n%s\n", BuildDetails())
}
// Version returns a string containing the dgraphVersion.
func Version() string {
return dgraphVersion
}
// Codename returns a string containing the dgraphCodename.
func Codename() string {
return dgraphCodename
}
// pattern for dev version = min. 7 hex digits of commit-hash.
var versionRe *regexp.Regexp = regexp.MustCompile(`-g[[:xdigit:]]{7,}`)
// 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 DevVersion() (matched bool) {
return versionRe.MatchString(dgraphVersion)
}
// 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 ExecutableChecksum() []byte {
execPath, err := os.Executable()
if err != nil {
return nil
}
execFile, err := os.Open(execPath)
if err != nil {
return nil
}
defer func() {
if err := execFile.Close(); err != nil {
glog.Warningf("error closing file: %v", err)
}
}()
h := sha256.New()
if _, err := io.Copy(h, execFile); err != nil {
return nil
}
return h.Sum(nil)
}