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

etcdctl: fix snapshot status accidentally modified the db file #8815

Merged
merged 1 commit into from
Nov 8, 2017

Conversation

zrss
Copy link

@zrss zrss commented Nov 3, 2017

etcdctl: snapshot status open bbolt with ReadOnly as true

this can avoid writing the freelist to the db file

@zrss zrss force-pushed the fix-dbstatus-unexpected-write branch from cfc2703 to 29ec881 Compare November 3, 2017 13:14
@zrss zrss changed the title fix etcdctl snapshot status accidentally modified the db file etcdctl: fix snapshot status accidentally modified the db file Nov 3, 2017
@zrss zrss force-pushed the fix-dbstatus-unexpected-write branch from 29ec881 to 4a2c9f7 Compare November 3, 2017 13:28
@xiang90
Copy link
Contributor

xiang90 commented Nov 3, 2017

lgtm.

@zrss i am curious about how did you find this out?

@@ -409,7 +409,7 @@ func dbStatus(p string) dbstatus {

ds := dbstatus{}

db, err := bolt.Open(p, 0400, nil)
db, err := bolt.Open(p, 0400, &bolt.Options{NoFreelistSync: true})
Copy link
Contributor

Choose a reason for hiding this comment

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

ReadOnly: true

@zrss zrss force-pushed the fix-dbstatus-unexpected-write branch from 4a2c9f7 to c20151f Compare November 4, 2017 01:16
@zrss
Copy link
Author

zrss commented Nov 4, 2017

@xiang90 er, i just wanna to check the count of keys in db file through snapshot status, but the db file is generated by snapshot save with a sha256, finally there is a sha256 mismatch error when i do the snapshot restore

@zrss
Copy link
Author

zrss commented Nov 4, 2017

@heyitsanthony fix

@xiang90
Copy link
Contributor

xiang90 commented Nov 4, 2017

@gyuho no need to backport this to 3.2. we never enabled nosyncfreelist in 3.2.

@@ -409,7 +409,7 @@ func dbStatus(p string) dbstatus {

ds := dbstatus{}

db, err := bolt.Open(p, 0400, nil)
db, err := bolt.Open(p, 0400, &bolt.Options{ReadOnly: true})
Copy link
Contributor

Choose a reason for hiding this comment

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

we still need the nofsync option. also the file is already opened as readonly (0400), it is strange that we write it somehow...

can you also add an e2e test for the case that you described to prevent any potential regression?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh. i looked at the open code in boltdb, it does not try to interpret the fileperm bit anyway...

Copy link
Contributor

Choose a reason for hiding this comment

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

only ReadOnly is OK; bbolt will detect if there's a free list or not, which is why it was rebuilding the free list here

Copy link
Author

Choose a reason for hiding this comment

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

er, i will add a e2e test for the integrity verification with ReadOnly Option soon

Copy link
Author

Choose a reason for hiding this comment

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

it seems there is no test case for etcdctl ... should i add a new test file for snapshot_command or somewhere else ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

@xiang90 PTAL

@zrss zrss force-pushed the fix-dbstatus-unexpected-write branch from c20151f to 1010611 Compare November 8, 2017 16:54
@zrss zrss force-pushed the fix-dbstatus-unexpected-write branch from 1010611 to 0ce02ab Compare November 8, 2017 17:08
@xiang90
Copy link
Contributor

xiang90 commented Nov 8, 2017

LGTM

@xiang90 xiang90 merged commit 21178f5 into etcd-io:master Nov 8, 2017
@zrss zrss deleted the fix-dbstatus-unexpected-write branch November 9, 2017 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants