Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(upgrade): ensure we run right version of Dgraph #8910

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions dgraphtest/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type LiveOpts struct {
}

// readGzFile reads the given file from disk completely and returns the content.
func readGzFile(c *LocalCluster, sf string) ([]byte, error) {
func readGzFile(sf string, encryption bool) ([]byte, error) {
fd, err := os.Open(sf)
if err != nil {
return nil, errors.Wrapf(err, "error opening file [%v]", sf)
Expand All @@ -61,15 +61,15 @@ func readGzFile(c *LocalCluster, sf string) ([]byte, error) {
}
}()

data, err := readGzData(c, fd)
data, err := readGzData(fd, encryption)
if err != nil {
return nil, errors.Wrapf(err, "error reading data from file [%v]", sf)
}
return data, nil
}

func readGzData(c *LocalCluster, r io.Reader) ([]byte, error) {
if c.conf.encryption {
func readGzData(r io.Reader, encryption bool) ([]byte, error) {
if encryption {
encKey, err := os.ReadFile(encKeyPath)
if err != nil {
return nil, errors.Wrap(err, "error reading the encryption key from disk")
Expand Down Expand Up @@ -97,11 +97,11 @@ func readGzData(c *LocalCluster, r io.Reader) ([]byte, error) {
return data, nil
}

func writeGzData(c *LocalCluster, data []byte) (io.Reader, error) {
func writeGzData(data []byte, encryption bool) (io.Reader, error) {
buf := bytes.NewBuffer(nil)

var w io.Writer = buf
if c.conf.encryption {
if encryption {
encKey, err := os.ReadFile(encKeyPath)
if err != nil {
return nil, errors.Wrap(err, "error reading the encryption key from disk")
Expand Down Expand Up @@ -144,7 +144,7 @@ func setDQLSchema(c *LocalCluster, files []string) error {
}

for _, sf := range files {
data, err := readGzFile(c, sf)
data, err := readGzFile(sf, c.conf.encryption)
if err != nil {
return err
}
Expand All @@ -164,7 +164,7 @@ func setGraphQLSchema(c *LocalCluster, files []string) error {
}

for _, sf := range files {
data, err := readGzFile(c, sf)
data, err := readGzFile(sf, c.conf.encryption)
if err != nil {
return err
}
Expand Down Expand Up @@ -306,7 +306,7 @@ func modifyACLEntries(c *LocalCluster, r io.Reader) (io.Reader, error) {
grootUIDNew = fmt.Sprintf("<%v>", grootUIDNew)
guardiansUIDNew = fmt.Sprintf("<%v>", guardiansUIDNew)

data, err := readGzData(c, r)
data, err := readGzData(r, c.conf.encryption)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -354,7 +354,7 @@ func modifyACLEntries(c *LocalCluster, r io.Reader) (io.Reader, error) {
}
data = bytes.Join(lines, []byte{'\n'})

return writeGzData(c, data)
return writeGzData(data, c.conf.encryption)
}

// LiveLoadFromExport runs the live loader from the output of dgraph export
Expand Down
36 changes: 30 additions & 6 deletions dgraphtest/local_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,29 +345,37 @@ func (c *LocalCluster) killContainer(dc dnode) error {

func (c *LocalCluster) HealthCheck(zeroOnly bool) error {
log.Printf("[INFO] checking health of containers")
for i := 0; i < c.conf.numZeros; i++ {
url, err := c.zeros[i].healthURL(c)
for _, zo := range c.zeros {
url, err := zo.healthURL(c)
if err != nil {
return errors.Wrap(err, "error getting health URL")
}
if err := c.containerHealthCheck(url); err != nil {
return err
}
log.Printf("[INFO] container [zero-%v] passed health check", i)
log.Printf("[INFO] container [%v] passed health check", zo.containerName)

if err := c.checkDgraphVersion(zo.containerName); err != nil {
return err
}
}
if zeroOnly {
return nil
}

for i := 0; i < c.conf.numAlphas; i++ {
url, err := c.alphas[i].healthURL(c)
for _, aa := range c.alphas {
url, err := aa.healthURL(c)
if err != nil {
return errors.Wrap(err, "error getting health URL")
}
if err := c.containerHealthCheck(url); err != nil {
return err
}
log.Printf("[INFO] container [alpha-%v] passed health check", i)
log.Printf("[INFO] container [%v] passed health check", aa.containerName)

if err := c.checkDgraphVersion(aa.containerName); err != nil {
return err
}
}
return nil
}
Expand Down Expand Up @@ -551,6 +559,7 @@ func (c *LocalCluster) Upgrade(version string, strategy UpgradeStrategy) error {
return errors.Wrapf(err, "error during login before upgrade")
}
}
// using -1 as namespace exports all the namespaces
if err := hc.Export(DefaultExportDir, -1); err != nil {
return errors.Wrap(err, "error taking export during upgrade")
}
Expand Down Expand Up @@ -763,6 +772,21 @@ func (c *LocalCluster) printLogs(containerID string) error {
return nil
}

func (c *LocalCluster) checkDgraphVersion(containerID string) error {
if c.GetVersion() == localVersion {
return nil
}

contLogs, err := c.getLogs(containerID)
if err != nil {
return errors.Wrapf(err, "error during checkDgraphVersion for container [%v]", containerID)
}
if !strings.Contains(contLogs, fmt.Sprintf("Dgraph version : %v", c.GetVersion())) {
return errors.Errorf("found different dgraph version than expected [%v]", c.GetVersion())
}
return nil
}

func (c *LocalCluster) getLogs(containerID string) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()
Expand Down