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

Enhance check command to detect duplicated keys in each bucket #301

Closed
wants to merge 1 commit into from
Closed

Enhance check command to detect duplicated keys in each bucket #301

wants to merge 1 commit into from

Conversation

ahrtr
Copy link
Member

@ahrtr ahrtr commented Nov 8, 2021

The current check command can't detect duplicated keys in each bucket. Please see issue 299 and 13456.

So this PR is to enhance the check command to detect the duplicated keys.

After applying the change in this PR, It can successfully detect the 3 duplicated keys in the db file provided in 7011. Please see the output below,

$ go run cmd/bbolt/main.go check ~/tmp/db
duplicated key: "\x00\x00\x00\x00\x00\x00\xfe\x9a_\x00\x00\x00\x00\x00\x00\x00\x00" found
duplicated key: "\x00\x00\x00\x00\x00\x00\xfe\x9b_\x00\x00\x00\x00\x00\x00\x00\x00" found
duplicated key: "\x00\x00\x00\x00\x00\x00\xfe\x9c_\x00\x00\x00\x00\x00\x00\x00\x00" found
3 errors found
invalid value
exit status 1

If the solution is accepted, then I may think about how to add some unit test. We can use the db.Info() interface method to get the raw data, and then try to add some duplicated keys.

cc @ptabor

@ptabor
Copy link
Contributor

ptabor commented Dec 21, 2022

I think that this PR is a functional subset of #225:

Tested it on etcd-io/etcd#7011 with the following results:

key[30]=(hex)000000000000fe9a5f0000000000000000 on leaf page(1798) needs to be < than key of the next element in ancestor (hex)000000000000fe9a5f0000000000000000. Pages stack: [2855 1922 1798]
key[31]=(hex)000000000000fe9b5f0000000000000000 on leaf page(1798) needs to be < than key of the next element in ancestor (hex)000000000000fe9a5f0000000000000000. Pages stack: [2855 1922 1798]
key[32]=(hex)000000000000fe9c5f0000000000000000 on leaf page(1798) needs to be < than key of the next element in ancestor (hex)000000000000fe9a5f0000000000000000. Pages stack: [2855 1922 1798]
3 errors found
invalid value
$ ./bbolt page ~/Downloads/pd/member/snap/db 1798
Page ID:    1798
Page Type:  leaf
Total Size: 4096 bytes
Item Count: 33

000000000000fe7c5f0000000000000000: 0a332f70642f363336333038333237303732383837383530332f726166742f722f303030303030303030303030303030313539343010fcfc0318fcfc0320012a4c08c47c12159699e24a26c84a43649f69fab1289683aaeb82ecc41a159699f4db315a9fca3c7b9e27f7762bc478368373022204081110112a0508c57c10132a0508c67c10252a0508c77c1026
000000000000fe7d5f0000000000000000: 0a212f70642f363336333038333237303732383837383530332f74696d657374616d70100418fdfc0320acbc032a08148ff938c0d34f81
000000000000fe7e5f0000000000000000: 0a212f70642f363336333038333237303732383837383530332f74696d657374616d70100418fefc0320adbc032a08148ff939769f3aea
000000000000fe7f5f0000000000000000: 0a212f70642f363336333038333237303732383837383530332f74696d657374616d70100418fffc0320aebc032a08148ff93a2c69a44e
...
000000000000fe985f0000000000000000: 0a212f70642f363336333038333237303732383837383530332f74696d657374616d7010041898fd0320bebc032a08148ff945773d41f5
000000000000fe995f0000000000000000: 0a212f70642f363336333038333237303732383837383530332f74696d657374616d7010041899fd0320bfbc032a08148ff9462a0df897
000000000000fe9a5f0000000000000000: 0a332f70642f363336333038333237303732383837383530332f726166742f722f3030303030303030303030303030303035353438109aed02189afd0320022a5308ac2b1215162400207a4e8fb3670f7542cd5a4ce9e42d301a8c1a151624358f5fd36d7201ac2c65e223b2d1b2a1f23cdd2204080e10162a0508ad2b10222a0508ae2b101f2a0508af2b10292a0508cc7c100e
000000000000fe9b5f0000000000000000: 0a212f70642f363336333038333237303732383837383530332f74696d657374616d701004189bfd0320c0bc032a08148ff946dfd98a45
000000000000fe9c5f0000000000000000: 0a332f70642f363336333038333237303732383837383530332f726166742f722f303030303030303030303030303030303630353710dafc02189cfd0320042a5308a92f1215168da953e80d3ff177d152ba1e00272360a6ebe7401a15168ddb19d22818a01a7bea0ada3538e8d48fb803fc2204080e10122a0508ab2f100c2a0508ac2f10272a0508df3510252a0508d57c100e
$ ./bbolt page ~/Downloads/pd/member/snap/db 1922
Page ID:    1922
Page Type:  branch
Total Size: 4096 bytes
Item Count: 111

000000000000fdfd5f0000000000000000: <pgid=1789>
000000000000fe1e5f0000000000000000: <pgid=1790>
000000000000fe3e5f0000000000000000: <pgid=1793>
000000000000fe5c5f0000000000000000: <pgid=1797>
000000000000fe7c5f0000000000000000: <pgid=1798>
000000000000fe9a5f0000000000000000: <pgid=1799>
000000000000feba5f0000000000000000: <pgid=1794>
000000000000fede5f0000000000000000: <pgid=1800>

I would propose closing it on behalf of #225:

@ahrtr ahrtr closed this Dec 22, 2022
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.

2 participants