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

Fix UAV migration bug: look up editableMappingsInfo versions in correct list #8378

Merged
merged 2 commits into from
Feb 7, 2025

Conversation

fm3
Copy link
Member

@fm3 fm3 commented Feb 5, 2025

Follow-up for #7917 – a bug in the migration led to some versions of the editableMappingInfo being skipped. We repaired this for the first migrated instance using the added python script.

@fm3 fm3 self-assigned this Feb 5, 2025
Copy link
Contributor

coderabbitai bot commented Feb 5, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a new script that inserts editable mapping information into a FossilDB database and updates the migration logic in an existing script. The new Python script uses command-line arguments, logging, and a gRPC call to perform database insertions. Additionally, the migration method now checks the correct mapping identifier when verifying the existence of a materialized version, with a reordering of the byte retrieval process.

Changes

File(s) Change Summary
tools/.../add_editable_mapping_info.py New Python script that sets up logging and CLI arguments; reads binary input; constructs and sends a gRPC request to insert editable mapping info into FossilDB; includes error handling and timing logs.
tools/.../migration.py Modified migrate_editable_mapping_info method in the Migration class to check against mapping_id instead of tracing_id, and moved the retrieval of value_bytes to occur only after the check.

Suggested labels

infrastructure

Suggested reviewers

  • normanrz

Poem

I'm a hopping little rabbit, coding with delight,
Skipping through the scripts on this bright database night.
New functions and tweaks are my carrot treats,
With every log and line, my heart joyfully beats.
Hoppity cheers for code that shines so right!
🐰💻

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@fm3 fm3 marked this pull request as ready for review February 6, 2025 14:42
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b946f8 and 49b70b7.

📒 Files selected for processing (2)
  • tools/migration-unified-annotation-versioning/add_editable_mapping_info.py (1 hunks)
  • tools/migration-unified-annotation-versioning/migration.py (1 hunks)
🔇 Additional comments (3)
tools/migration-unified-annotation-versioning/add_editable_mapping_info.py (2)

1-10: LGTM! Clean and well-organized imports.

The imports are logically grouped and include all necessary dependencies for logging, argument parsing, and FossilDB communication.


35-36: LGTM! Standard Python entry point pattern.

The entry point follows the standard Python pattern for script execution.

tools/migration-unified-annotation-versioning/migration.py (1)

460-462: LGTM! Bug fix for version lookup.

The fix correctly uses mapping_id instead of tracing_id when checking for materialized versions in the layer version mapping. This aligns with the PR objectives to fix the UAV migration bug where editableMappingInfo versions were being looked up in the wrong list.

Let's verify that this is the only place where we need to make this change:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Search for other potential places where we might need to make similar changes
ast-grep --pattern 'layer_version_mapping[$_][$_]'

Length of output: 675


Verification of Version Lookup Fix in Editable Mapping Info

The fix in the migrate_editable_mapping_info function (lines 460–463) correctly switches to using mapping_id for version lookup. Our search shows that the other usages of layer_version_mapping (in lines 319, 345, and 427) still use tracing_id or tracing_or_mapping_id in different contexts. This indicates that the change is isolated to editable mapping info where the correct key is indeed mapping_id, and the other occurrences remain intentional.

Comment on lines +12 to +29
def main():
logger.info("Hello from add_editable_mapping_info")
setup_logging()
parser = argparse.ArgumentParser()
parser.add_argument("--fossil", type=str, help="Fossildb host and port. Example: localhost:7155", required=True)
parser.add_argument("--editable_mapping_info_file", type=str, help="path to binary input file to put", required=True)
parser.add_argument("--tracingId", type=str, help="tracingId to put the entry to", required=True)
parser.add_argument("--version", type=int, help="version number to put the entry to", required=True)
args = parser.parse_args()
before = time.time()
stub = connect_to_fossildb(args.fossil, "target")
with open(args.editable_mapping_info_file, 'rb') as infile:
bytes_to_put = infile.read()

logger.info(f"putting {len(bytes_to_put)} bytes of type {type(bytes_to_put)} at {args.tracingId} v{args.version}")
reply = stub.Put(proto.PutRequest(collection="editableMappingsInfo", key=args.tracingId, version=args.version, value=bytes_to_put))
assert_grpc_success(reply)
log_since(before, "Inserting one editable mapping info entry")
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for file operations and gRPC calls.

The script needs better error handling for:

  1. File operations when reading the binary input file
  2. gRPC connection failures
  3. Invalid input validation

Apply this diff to add error handling:

 def main():
     logger.info("Hello from add_editable_mapping_info")
     setup_logging()
     parser = argparse.ArgumentParser()
     parser.add_argument("--fossil", type=str, help="Fossildb host and port. Example: localhost:7155", required=True)
     parser.add_argument("--editable_mapping_info_file", type=str, help="path to binary input file to put", required=True)
     parser.add_argument("--tracingId", type=str, help="tracingId to put the entry to", required=True)
     parser.add_argument("--version", type=int, help="version number to put the entry to", required=True)
     args = parser.parse_args()
     before = time.time()
-    stub = connect_to_fossildb(args.fossil, "target")
-    with open(args.editable_mapping_info_file, 'rb') as infile:
-        bytes_to_put = infile.read()
+    try:
+        if args.version < 0:
+            raise ValueError("Version number must be non-negative")
+        
+        stub = connect_to_fossildb(args.fossil, "target")
+        
+        try:
+            with open(args.editable_mapping_info_file, 'rb') as infile:
+                bytes_to_put = infile.read()
+        except IOError as e:
+            logger.error(f"Failed to read input file: {e}")
+            raise
 
-    logger.info(f"putting {len(bytes_to_put)} bytes of type {type(bytes_to_put)} at {args.tracingId} v{args.version}")
-    reply = stub.Put(proto.PutRequest(collection="editableMappingsInfo", key=args.tracingId, version=args.version, value=bytes_to_put))
-    assert_grpc_success(reply)
-    log_since(before, "Inserting one editable mapping info entry")
+        if not bytes_to_put:
+            raise ValueError("Input file is empty")
+            
+        logger.info(f"putting {len(bytes_to_put)} bytes of type {type(bytes_to_put)} at {args.tracingId} v{args.version}")
+        try:
+            reply = stub.Put(proto.PutRequest(collection="editableMappingsInfo", key=args.tracingId, version=args.version, value=bytes_to_put))
+            assert_grpc_success(reply)
+            log_since(before, "Inserting one editable mapping info entry")
+        except Exception as e:
+            logger.error(f"Failed to put data to FossilDB: {e}")
+            raise
+    except Exception as e:
+        logger.error(f"Script failed: {e}")
+        sys.exit(1)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def main():
logger.info("Hello from add_editable_mapping_info")
setup_logging()
parser = argparse.ArgumentParser()
parser.add_argument("--fossil", type=str, help="Fossildb host and port. Example: localhost:7155", required=True)
parser.add_argument("--editable_mapping_info_file", type=str, help="path to binary input file to put", required=True)
parser.add_argument("--tracingId", type=str, help="tracingId to put the entry to", required=True)
parser.add_argument("--version", type=int, help="version number to put the entry to", required=True)
args = parser.parse_args()
before = time.time()
stub = connect_to_fossildb(args.fossil, "target")
with open(args.editable_mapping_info_file, 'rb') as infile:
bytes_to_put = infile.read()
logger.info(f"putting {len(bytes_to_put)} bytes of type {type(bytes_to_put)} at {args.tracingId} v{args.version}")
reply = stub.Put(proto.PutRequest(collection="editableMappingsInfo", key=args.tracingId, version=args.version, value=bytes_to_put))
assert_grpc_success(reply)
log_since(before, "Inserting one editable mapping info entry")
def main():
logger.info("Hello from add_editable_mapping_info")
setup_logging()
parser = argparse.ArgumentParser()
parser.add_argument("--fossil", type=str, help="Fossildb host and port. Example: localhost:7155", required=True)
parser.add_argument("--editable_mapping_info_file", type=str, help="path to binary input file to put", required=True)
parser.add_argument("--tracingId", type=str, help="tracingId to put the entry to", required=True)
parser.add_argument("--version", type=int, help="version number to put the entry to", required=True)
args = parser.parse_args()
before = time.time()
try:
if args.version < 0:
raise ValueError("Version number must be non-negative")
stub = connect_to_fossildb(args.fossil, "target")
try:
with open(args.editable_mapping_info_file, 'rb') as infile:
bytes_to_put = infile.read()
except IOError as e:
logger.error(f"Failed to read input file: {e}")
raise
if not bytes_to_put:
raise ValueError("Input file is empty")
logger.info(f"putting {len(bytes_to_put)} bytes of type {type(bytes_to_put)} at {args.tracingId} v{args.version}")
try:
reply = stub.Put(proto.PutRequest(collection="editableMappingsInfo", key=args.tracingId, version=args.version, value=bytes_to_put))
assert_grpc_success(reply)
log_since(before, "Inserting one editable mapping info entry")
except Exception as e:
logger.error(f"Failed to put data to FossilDB: {e}")
raise
except Exception as e:
logger.error(f"Script failed: {e}")
sys.exit(1)

Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer left a comment

Choose a reason for hiding this comment

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

Look g8 I r8 8/8

Thanks for fixing this 🙏

@fm3 fm3 enabled auto-merge (squash) February 7, 2025 15:18
@fm3 fm3 merged commit 5d04993 into master Feb 7, 2025
3 checks passed
@fm3 fm3 deleted the migration-right-editable-mapping-versions branch February 7, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants