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

Optimize isValidPath check in MetadataStore #12663

Conversation

Jason918
Copy link
Contributor

@Jason918 Jason918 commented Nov 8, 2021

Motivation

  1. There is a logic error in original LocalMemoryMetadataStore#isValidPath with this code line 239

return !path.equals("/") || !path.endsWith("/");

The "||" operator should be "&&", to forbids path ends with "/"

  1. Further more, as we can implement other MetadataStore based on etcd or other external storage system. The path check function should be added to AbstractMetadataStore, and get checked before any operations.

Modifications

  1. Fixed the logic error in isValidPath and moved it to AbstractMetadataStore.
  2. Check path before each operation in AbstractMetadataStore.
  3. Add MetadataStoreException.InvalidPathException

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • org.apache.pulsar.metadata.LocalMemoryMetadataStoreTest#testPathValid

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (no)
  • The schema: (no)
  • The default values of configurations: (no)
  • The wire protocol: (no)
  • The rest endpoints: (no)
  • The admin cli options: (no)
  • Anything that affects deployment: (no)

Documentation

Check the box below and label this PR (if you have committer privilege).

Need to update docs?

  • doc

Added doc in isValidPath
No user doc needed.

@github-actions github-actions bot added the doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. label Nov 8, 2021
@Jason918
Copy link
Contributor Author

Jason918 commented Nov 9, 2021

/pulsarbot run-failure-checks

@Jason918 Jason918 force-pushed the fix_error_in_LocalMemoryMetadataStore#isValidPath branch from 0528c16 to 99f7294 Compare November 10, 2021 03:27
@Jason918
Copy link
Contributor Author

/pulsarbot run-failure-checks

@codelipenghui codelipenghui merged commit e281449 into apache:master Nov 12, 2021
@Jason918 Jason918 deleted the fix_error_in_LocalMemoryMetadataStore#isValidPath branch November 12, 2021 06:10
eolivelli pushed a commit to eolivelli/pulsar that referenced this pull request Nov 29, 2021
### Motivation

1. There is a logic error in original LocalMemoryMetadataStore#isValidPath with this code line 239
>  return !path.equals("/") || !path.endsWith("/");

The "||" operator should be "&&", to forbids path ends with "/"

2. Further more, as we can implement other MetadataStore based on etcd or other external storage system. The path check function should be added to AbstractMetadataStore, and get checked before any operations.

### Modifications

1. Fixed the logic error in isValidPath and moved it to AbstractMetadataStore.
2. Check path before each operation in AbstractMetadataStore.
3. Add MetadataStoreException.InvalidPathException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Your PR contains doc changes, no matter whether the changes are in markdown or code files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants