Skip to content

Commit

Permalink
fix(dgraph): Fix dgraph crash on windows (#7261)
Browse files Browse the repository at this point in the history
There were two issues on windows

1. We were trying to delete a file with open file descriptors. This
doesn't work on windows. The PR dgraph-io/ristretto#242 in ristretto fixes this.
2. We were using path.Join instead of filepath.Join. The path package is
supposed to be used only on Unix systems. In windows the "" is the path
separator instead of "/".
  • Loading branch information
Ibrahim Jarif authored Jan 14, 2021
1 parent 95859e0 commit 5aec243
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 59 deletions.
4 changes: 2 additions & 2 deletions contrib/jepsen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"net/http"
"os"
"os/exec"
"path"
"path/filepath"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -349,7 +349,7 @@ func inCi() bool {
}

func saveJaegerTracesToJepsen(jepsenPath string) {
dst := path.Join(jepsenPath, "dgraph", "store", "current", "jaeger")
dst := filepath.Join(jepsenPath, "dgraph", "store", "current", "jaeger")
cmd := command("sudo", "docker", "cp", "jaeger:/working/jaeger", dst)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down
3 changes: 1 addition & 2 deletions dgraph/cmd/cert/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"

"github.com/pkg/errors"
Expand Down Expand Up @@ -278,7 +277,7 @@ func createCerts(opt *options) error {
}

// no path then save it in certsDir.
if path.Base(opt.caKey) == opt.caKey {
if filepath.Base(opt.caKey) == opt.caKey {
opt.caKey = filepath.Join(opt.dir, opt.caKey)
}
opt.caCert = filepath.Join(opt.dir, defaultCACert)
Expand Down
4 changes: 2 additions & 2 deletions dgraph/cmd/live/load-json/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
"runtime"
"strings"
"testing"
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestLiveLoadJSONMultipleFiles(t *testing.T) {

func TestMain(m *testing.M) {
_, thisFile, _, _ := runtime.Caller(0)
testDataDir = path.Dir(thisFile)
testDataDir = filepath.Dir(thisFile)

var err error
dg, err = testutil.DgraphClientWithGroot(testutil.SockAddr)
Expand Down
4 changes: 2 additions & 2 deletions dgraph/cmd/live/load-uids/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
"regexp"
"runtime"
"strings"
Expand Down Expand Up @@ -375,7 +375,7 @@ func TestMain(m *testing.M) {
fmt.Printf("alphaExportPath: %s\n", alphaExportPath)

_, thisFile, _, _ := runtime.Caller(0)
testDataDir = path.Dir(thisFile)
testDataDir = filepath.Dir(thisFile)
fmt.Printf("Using test data dir: %s\n", testDataDir)

var err error
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/dgraph-io/gqlgen v0.13.2
github.com/dgraph-io/gqlparser/v2 v2.1.2
github.com/dgraph-io/graphql-transport-ws v0.0.0-20200916064635-48589439591b
github.com/dgraph-io/ristretto v0.0.4-0.20210104064432-d7c5d7a71e89
github.com/dgraph-io/ristretto v0.0.4-0.20210108140656-b1486d8516f2
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ github.com/dgraph-io/gqlparser/v2 v2.1.2/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P
github.com/dgraph-io/graphql-transport-ws v0.0.0-20200916064635-48589439591b h1:PDEhlwHpkEQ5WBfOOKZCNZTXFDGyCEWTYDhxGQbyIpk=
github.com/dgraph-io/graphql-transport-ws v0.0.0-20200916064635-48589439591b/go.mod h1:7z3c/5w0sMYYZF5bHsrh8IH4fKwG5O5Y70cPH1ZLLRQ=
github.com/dgraph-io/ristretto v0.0.4-0.20201205013540-bafef7527542/go.mod h1:tv2ec8nA7vRpSYX7/MbP52ihrUMXIHit54CQMq8npXQ=
github.com/dgraph-io/ristretto v0.0.4-0.20210104064432-d7c5d7a71e89 h1:uYRSuTAviO9ijHJQ9Dycui3mKVUSBoxXKQTBjkZDhG0=
github.com/dgraph-io/ristretto v0.0.4-0.20210104064432-d7c5d7a71e89/go.mod h1:tv2ec8nA7vRpSYX7/MbP52ihrUMXIHit54CQMq8npXQ=
github.com/dgraph-io/ristretto v0.0.4-0.20210108140656-b1486d8516f2 h1:Ii2KMtC40rP1jJB08GVFfQh/NEca2LBjKokO45N7xes=
github.com/dgraph-io/ristretto v0.0.4-0.20210108140656-b1486d8516f2/go.mod h1:tv2ec8nA7vRpSYX7/MbP52ihrUMXIHit54CQMq8npXQ=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 h1:CaO/zOnF8VvUfEbhRatPcwKVWamvbYd8tQGRWacE9kU=
Expand Down
4 changes: 2 additions & 2 deletions graphql/testdata/datagen/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"log"
"net/url"
"os"
"path"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -111,7 +111,7 @@ func initConfig() {
}

// Search config in home directory with name ".datagen" (without extension).
viper.AddConfigPath(path.Join(home, ".config", "datagen"))
viper.AddConfigPath(filepath.Join(home, ".config", "datagen"))
viper.SetConfigName("conf")
}

Expand Down
8 changes: 4 additions & 4 deletions graphql/testdata/datagen/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/spf13/viper"
"io/ioutil"
"log"
"math/rand"
"net/http"
"os"
"path"
"path/filepath"
"sort"
"strconv"
"strings"
"time"

"github.com/spf13/viper"
)

const (
Expand Down Expand Up @@ -229,12 +229,12 @@ func generateDishes(rest *restaurant) []dish {

func readRestaurantData() (dataFile, error) {
restaurantDataFile := viper.GetString(restaurantDataFilePath)
if !path.IsAbs(restaurantDataFile) {
if !filepath.IsAbs(restaurantDataFile) {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return nil, err
}
restaurantDataFile = path.Join(dir, restaurantDataFile)
restaurantDataFile = filepath.Join(dir, restaurantDataFile)
}

b, err := ioutil.ReadFile(restaurantDataFile)
Expand Down
6 changes: 3 additions & 3 deletions raftwal/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"encoding/binary"
"fmt"
"os"
"path"
"path/filepath"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -92,7 +92,7 @@ type logFile struct {
}

func logFname(dir string, id int64) string {
return path.Join(dir, fmt.Sprintf("%05d%s", id, logSuffix))
return filepath.Join(dir, fmt.Sprintf("%05d%s", id, logSuffix))
}

// openLogFile opens a logFile in the given directory. The filename is
Expand Down Expand Up @@ -275,7 +275,7 @@ func getLogFiles(dir string) ([]*logFile, error) {
seen := make(map[int64]struct{})

for _, fpath := range entryFiles {
_, fname := path.Split(fpath)
_, fname := filepath.Split(fpath)
fname = strings.TrimSuffix(fname, logSuffix)

fid, err := strconv.ParseInt(fname, 10, 64)
Expand Down
6 changes: 3 additions & 3 deletions systest/1million/1million_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9285,8 +9285,8 @@ func Test1Million(t *testing.T) {
}

func TestMain(m *testing.M) {
noschemaFile := path.Join(testutil.TestDataDirectory, "1million-noindex.schema")
rdfFile := path.Join(testutil.TestDataDirectory, "1million.rdf.gz")
noschemaFile := filepath.Join(testutil.TestDataDirectory, "1million-noindex.schema")
rdfFile := filepath.Join(testutil.TestDataDirectory, "1million.rdf.gz")
if err := testutil.MakeDirEmpty([]string{"out/0", "out/1", "out/2"}); err != nil {
os.Exit(1)
}
Expand All @@ -9304,7 +9304,7 @@ func TestMain(m *testing.M) {
fmt.Printf("Error while bringin up alphas. Error: %v\n", err)
cleanupAndExit(1)
}
schemaFile := path.Join(testutil.TestDataDirectory, "1million.schema")
schemaFile := filepath.Join(testutil.TestDataDirectory, "1million.schema")
client, err := testutil.DgraphClient(testutil.ContainerAddr("alpha1", 9080))
if err != nil {
fmt.Printf("Error while creating client. Error: %v\n", err)
Expand Down
6 changes: 3 additions & 3 deletions systest/21million/bulk/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package bulk

import (
"os"
"path"
"path/filepath"

"github.com/dgraph-io/dgraph/systest/21million/common"
"github.com/dgraph-io/dgraph/testutil"
Expand All @@ -31,8 +31,8 @@ func TestQueries(t *testing.T) {
}

func TestMain(m *testing.M) {
schemaFile := path.Join(testutil.TestDataDirectory, "21million.schema")
rdfFile := path.Join(testutil.TestDataDirectory, "21million.rdf.gz")
schemaFile := filepath.Join(testutil.TestDataDirectory, "21million.schema")
rdfFile := filepath.Join(testutil.TestDataDirectory, "21million.rdf.gz")
if err := testutil.MakeDirEmpty([]string{"out/0", "out/1", "out/2"}); err != nil {
os.Exit(1)
}
Expand Down
8 changes: 4 additions & 4 deletions systest/21million/common/run_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package common
import (
"context"
"io/ioutil"
"path"
"path/filepath"
"runtime"
"strings"
"testing"
Expand All @@ -39,7 +39,7 @@ import (

func TestQueriesFor21Million(t *testing.T) {
_, thisFile, _, _ := runtime.Caller(0)
queryDir := path.Join(path.Dir(thisFile), "../queries")
queryDir := filepath.Join(filepath.Dir(thisFile), "../queries")

// For this test we DON'T want to start with an empty database.
dg, err := testutil.DgraphClient(testutil.ContainerAddr("alpha1", 9080))
Expand All @@ -59,7 +59,7 @@ func TestQueriesFor21Million(t *testing.T) {
continue
}
t.Run(file.Name(), func(t *testing.T) {
filename := path.Join(queryDir, file.Name())
filename := filepath.Join(queryDir, file.Name())
reader, cleanup := chunker.FileReader(filename, nil)
bytes, err := ioutil.ReadAll(reader)
if err != nil {
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestQueriesFor21Million(t *testing.T) {

t.Logf("running %s", file.Name())
//if *savedir != "" {
// savepath = path.Join(*savedir, file.Name())
// savepath = filepath.Join(*savedir, file.Name())
//}

testutil.CompareJSON(t, bodies[1], string(resp.GetJson()))
Expand Down
6 changes: 3 additions & 3 deletions systest/21million/live/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package bulk

import (
"os"
"path"
"path/filepath"

"github.com/dgraph-io/dgraph/testutil"

Expand All @@ -32,8 +32,8 @@ func TestQueries(t *testing.T) {
}

func TestMain(m *testing.M) {
schemaFile := path.Join(testutil.TestDataDirectory, "21million.schema")
rdfFile := path.Join(testutil.TestDataDirectory, "21million.rdf.gz")
schemaFile := filepath.Join(testutil.TestDataDirectory, "21million.schema")
rdfFile := filepath.Join(testutil.TestDataDirectory, "21million.rdf.gz")
if err := testutil.LiveLoad(testutil.LiveOpts{
Alpha: testutil.ContainerAddr("alpha1", 9080),
Zero: testutil.SockAddrZero,
Expand Down
6 changes: 3 additions & 3 deletions systest/21million/ludicrous/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package bulk

import (
"os"
"path"
"path/filepath"

"github.com/dgraph-io/dgraph/testutil"

Expand All @@ -31,8 +31,8 @@ import (
//}

func TestMain(m *testing.M) {
schemaFile := path.Join(testutil.TestDataDirectory, "21million.schema")
rdfFile := path.Join(testutil.TestDataDirectory, "21million.rdf.gz")
schemaFile := filepath.Join(testutil.TestDataDirectory, "21million.schema")
rdfFile := filepath.Join(testutil.TestDataDirectory, "21million.rdf.gz")

if err := testutil.LiveLoad(testutil.LiveOpts{
Alpha: testutil.ContainerAddr("alpha1", 9080),
Expand Down
8 changes: 4 additions & 4 deletions systest/ludicrous/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"context"
"flag"
"io/ioutil"
"path"
"path/filepath"
"runtime"
"strings"
"testing"
Expand All @@ -43,7 +43,7 @@ var quiet = flag.Bool("quiet", false,

func TestQueries(t *testing.T) {
_, thisFile, _, _ := runtime.Caller(0)
queryDir := path.Join(path.Dir(thisFile), "queries")
queryDir := filepath.Join(filepath.Dir(thisFile), "queries")

// For this test we DON'T want to start with an empty database.
dg, err := testutil.DgraphClient(testutil.SockAddr)
Expand All @@ -63,7 +63,7 @@ func TestQueries(t *testing.T) {
continue
}
t.Run(file.Name(), func(t *testing.T) {
filename := path.Join(queryDir, file.Name())
filename := filepath.Join(queryDir, file.Name())
reader, cleanup := chunker.FileReader(filename, nil)
bytes, err := ioutil.ReadAll(reader)
if err != nil {
Expand All @@ -87,7 +87,7 @@ func TestQueries(t *testing.T) {

t.Logf("running %s", file.Name())
if *savedir != "" {
savepath = path.Join(*savedir, file.Name())
savepath = filepath.Join(*savedir, file.Name())
}

if !testutil.EqualJSON(t, bodies[1], string(resp.GetJson()), savepath, *quiet) {
Expand Down
6 changes: 3 additions & 3 deletions systest/online-restore/online_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"runtime"
"strings"
"testing"
Expand Down Expand Up @@ -98,7 +98,7 @@ func disableDraining(t *testing.T) {

func runQueries(t *testing.T, dg *dgo.Dgraph, shouldFail bool) {
_, thisFile, _, _ := runtime.Caller(0)
queryDir := path.Join(path.Dir(thisFile), "queries")
queryDir := filepath.Join(filepath.Dir(thisFile), "queries")

files, err := ioutil.ReadDir(queryDir)
require.NoError(t, err)
Expand All @@ -107,7 +107,7 @@ func runQueries(t *testing.T, dg *dgo.Dgraph, shouldFail bool) {
if !strings.HasPrefix(file.Name(), "query-") {
continue
}
filename := path.Join(queryDir, file.Name())
filename := filepath.Join(queryDir, file.Name())
reader, cleanup := chunker.FileReader(filename, nil)
bytes, err := ioutil.ReadAll(reader)
require.NoError(t, err)
Expand Down
9 changes: 4 additions & 5 deletions t/t.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"os"
"os/exec"
"os/signal"
"path"
"path/filepath"
"sort"
"strconv"
Expand Down Expand Up @@ -214,7 +213,7 @@ func runTestsFor(ctx context.Context, pkg, prefix string) error {

func hasTestFiles(pkg string) bool {
dir := strings.Replace(pkg, "github.com/dgraph-io/dgraph/", "", 1)
dir = path.Join(*baseDir, dir)
dir = filepath.Join(*baseDir, dir)

hasTests := false
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
Expand Down Expand Up @@ -248,7 +247,7 @@ func runTests(taskCh chan task, closer *z.Closer) error {
closer.Done()
}()

defaultCompose := path.Join(*baseDir, "dgraph/docker-compose.yml")
defaultCompose := filepath.Join(*baseDir, "dgraph/docker-compose.yml")
prefix := getClusterPrefix()

var started, stopped bool
Expand Down Expand Up @@ -353,7 +352,7 @@ func findPackagesFor(testName string) []string {
for scan.Scan() {
fname := scan.Text()
if strings.HasSuffix(fname, "_test.go") {
dir := strings.Replace(path.Dir(fname), *baseDir, "", 1)
dir := strings.Replace(filepath.Dir(fname), *baseDir, "", 1)
dirs = append(dirs, dir)
}
}
Expand Down Expand Up @@ -424,7 +423,7 @@ type task struct {

func composeFileFor(pkg string) string {
dir := strings.Replace(pkg, "github.com/dgraph-io/dgraph/", "", 1)
return path.Join(*baseDir, dir, "docker-compose.yml")
return filepath.Join(*baseDir, dir, "docker-compose.yml")
}

func getPackages() []task {
Expand Down
Loading

0 comments on commit 5aec243

Please sign in to comment.