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

add backup rs tests #1473

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

add backup rs tests #1473

wants to merge 2 commits into from

Conversation

Vitaliy3000
Copy link

@Vitaliy3000 Vitaliy3000 commented May 10, 2023

Mongodb

Pull request description

Describe what this PR fix

New tests was added for describing of restoring replica set from binary backup.

@Vitaliy3000 Vitaliy3000 requested a review from a team as a code owner May 10, 2023 16:20
time.Sleep(time.Second * 20)

return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need new line (\n) in the end file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -534,12 +534,34 @@ func (mc *MongoCtl) StartMongod() error {
return err
}


func (mc *MongoCtl) FetchLogs(text string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be we can name function as GrepLogs? =) Fetch is similar git fetch - extract some inforation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


func (mc *MongoCtl) FetchLogs(text string) (string, error) {
exc, err := mc.runCmd("grep", fmt.Sprintf("\"%s\"", text), "/var/log/mongodb/mongod.log")
tracelog.ErrorLogger.Printf("Command failed %s", exc.Stderr())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log error every time? may be it need if err != nil?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

tracelog.ErrorLogger.Printf("Command failed %s", exc.Stderr())

if err != nil{
if exc.ExitCode == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spend some time to understand why =)
Can we add comment like - we don't find any text, so we should return empty line as result
?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -98,3 +100,87 @@ func (tctx *TestContext) restoreMongoBinaryBackup(backupNumber int, container st

return nil
}


func (tctx *TestContext) restoreMongoReplSetBinaryBackupAsNonInitialized(backupNumber int, containers string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does the function have suffix "AsNonInitialized"? we do initialization in this function =)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed initialization from function

return tctx.restoreMongoReplSetBinaryBackup(backupNumber, containerNames)
}

func (tctx *TestContext) restoreMongoReplSetBinaryBackup(backupNumber int, containerNames []string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very big function, need to split on multiple logical functions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}

for _, mongoCtl := range mongoCtlList {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be we can union with previous loop?

for i, container := range containerNames {
  walg[i]...
  mongoCtl[i]...
  if i == 0 {
    tctx.initiateReplSet(container)
  }
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

firstly backup, lately start mongo, otherwise it's wrong

}

for _, container := range containerNames {
if err := tctx.initiateReplSet(container); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm... we need initiate only for one mongodb =)
may be it works, because of in InitReplSet function check IsMaster return master
anyway see previous comment, lets union in single loop

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it

}

// time for sync
time.Sleep(time.Second * 20)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep with big time is bad architecture =)
we need loop with check and sleep small time. but the best solution - we need use steps in feature files 'Then mongodb role is primary on mongodb01' and 'And mongodb role is secondary on mongodb02'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it, added func waitSecondariesSync

ctx.Step(`^at least one oplog archive exists in storage$`, tctx.oplogArchiveIsNotEmpty)
ctx.Step(`^we purge oplog archives via ([^\s]*)$`, tctx.purgeOplogArchives)
ctx.Step(`^oplog archiving is enabled on ([^\s]*)$`, tctx.enableOplogPush)
ctx.Step(`^we restore from #(\d+) backup to "([^"]*)" timestamp to ([^\s]*)$`, tctx.replayOplog)

ctx.Step(`^mongodb not has initial sync on ([^\s]+)$`, tctx.checkInitialSync)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be: not has -> doesn't have
?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants