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 Inspect method & command to inspect db structure #674

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

ahrtr
Copy link
Member

@ahrtr ahrtr commented Jan 11, 2024

Example 1: inspect etcd db file

$ ./bbolt inspect etcd_data_db_file 
{
    "name": "root",
    "keyN": 0,
    "buckets": [
        {
            "name": "alarm",
            "keyN": 0
        },
        {
            "name": "auth",
            "keyN": 2
        },
        {
            "name": "authRoles",
            "keyN": 1
        },
        {
            "name": "authUsers",
            "keyN": 1
        },
        {
            "name": "cluster",
            "keyN": 1
        },
        {
            "name": "key",
            "keyN": 1285
        },
        {
            "name": "lease",
            "keyN": 2
        },
        {
            "name": "members",
            "keyN": 1
        },
        {
            "name": "members_removed",
            "keyN": 0
        },
        {
            "name": "meta",
            "keyN": 3
        }
    ]
}

Example 2: inspect the db file generated in test case TestBucket_Inspect

$ ./bbolt inspect TestBucket_Inspect_db
{
    "name": "root",
    "keyN": 0,
    "buckets": [
        {
            "name": "b1",
            "keyN": 3,
            "buckets": [
                {
                    "name": "b1_1",
                    "keyN": 6
                },
                {
                    "name": "b1_2",
                    "keyN": 7
                },
                {
                    "name": "b1_3",
                    "keyN": 8
                }
            ]
        },
        {
            "name": "b2",
            "keyN": 4,
            "buckets": [
                {
                    "name": "b2_1",
                    "keyN": 10
                },
                {
                    "name": "b2_2",
                    "keyN": 12,
                    "buckets": [
                        {
                            "name": "b2_2_1",
                            "keyN": 2
                        },
                        {
                            "name": "b2_2_2",
                            "keyN": 3
                        }
                    ]
                },
                {
                    "name": "b2_3",
                    "keyN": 11
                }
            ]
        }
    ]
}

@ahrtr
Copy link
Member Author

ahrtr commented Jan 11, 2024

@fuweid @tjungblu @Elbehery

@ahrtr ahrtr force-pushed the inspect_20240111 branch 4 times, most recently from 7f850e7 to a3c8bfa Compare January 11, 2024 15:07
Also added a related command: bbolt inspect db

The outputed etcd data structure:
{
    "name": "root",
    "keyN": 0,
    "children": [
        {
            "name": "alarm",
            "keyN": 0
        },
        {
            "name": "auth",
            "keyN": 2
        },
        {
            "name": "authRoles",
            "keyN": 1
        },
        {
            "name": "authUsers",
            "keyN": 1
        },
        {
            "name": "cluster",
            "keyN": 1
        },
        {
            "name": "key",
            "keyN": 1285
        },
        {
            "name": "lease",
            "keyN": 2
        },
        {
            "name": "members",
            "keyN": 1
        },
        {
            "name": "members_removed",
            "keyN": 0
        },
        {
            "name": "meta",
            "keyN": 3
        }
    ]
}

Signed-off-by: Benjamin Wang <[email protected]>
@ahrtr ahrtr added this to the v1.4.0 milestone Jan 11, 2024
Copy link
Member

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

@ahrtr ahrtr merged commit 87fb5de into etcd-io:main Jan 11, 2024
16 checks passed
@ahrtr ahrtr deleted the inspect_20240111 branch June 26, 2024 15:38
@@ -170,6 +170,7 @@ The commands are:
pages print list of pages with their types
page-item print the key and value of a page item.
stats iterate over all pages and generate usage stats
inspect inspect the structure of the database

Choose a reason for hiding this comment

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

Just curious: was there a reason not to add this to the Run method as well?

Currently it seems the inspect command does not work, but the code is there thanks to this commit. trying to understand if that's intentional

Copy link
Member Author

Choose a reason for hiding this comment

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

When the commands are not found in the Run method, bbolt will automatically try to run the cobra commands,

bbolt/cmd/bbolt/main.go

Lines 68 to 69 in 92c7414

} else if err == ErrUnknownCommand {
cobraExecute()

Currently it seems the inspect command does not work

Have you tried it out? This isn't the first time I see this false statement. Please try it out, let me know whether you really have issue.

Choose a reason for hiding this comment

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

Using 1.3.11 I get:

$ bbolt inspect /tmp/meta.db
unknown command

Choose a reason for hiding this comment

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

Ok it seems the latest released version v1.3.11 does not have the changes you referenced (

func main() {
). It was confusing though because the README references this command. I suspect that's why others are tripping up as well

Copy link
Member Author

Choose a reason for hiding this comment

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

New features, including this one, only go into main branch.

So please try the main branch or v1.4.0-beta.0

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

3 participants