Skip to content

Fix HadoopFs token lock behavior for DBFS filesystem#603

Merged
yruslan merged 3 commits into
mainfrom
bugfix/hadoopfs-locking-fs-error
May 30, 2025
Merged

Fix HadoopFs token lock behavior for DBFS filesystem#603
yruslan merged 3 commits into
mainfrom
bugfix/hadoopfs-locking-fs-error

Conversation

@yruslan

@yruslan yruslan commented May 30, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added an option to control file overwrite behavior when writing files.
  • Bug Fixes

    • Improved file reading to handle large files safely and allocate buffers correctly.
    • Enhanced error handling when reading file contents.
  • Refactor

    • Reduced synchronization scope in lock release operations for better performance.
    • Renamed local variables for consistency.
  • Tests

    • Updated tests to reflect changes in file writing method parameters.

@coderabbitai

coderabbitai Bot commented May 30, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes update file utility and locking logic. The file write method now accepts an overwrite flag, file reading is made more robust, and error handling is improved. Lock release synchronization is minimized, and test mocks are adjusted for the new method signature. No core logic or control flow is fundamentally changed.

Changes

File(s) Change Summary
pramen/core/src/main/scala/za/co/absa/pramen/core/lock/TokenLockBase.scala Reduced synchronization scope in release(); renamed local variable in shutdown hook for consistency.
pramen/core/src/main/scala/za/co/absa/pramen/core/utils/FsUtils.scala Added overwrite parameter to writeFile; improved file size handling and error logging in file reading methods.
pramen/core/src/test/scala/za/co/absa/pramen/core/tests/utils/FsUtilsSuite.scala Updated mocks to match new writeFile signature with overwrite boolean parameter.

Possibly related PRs

  • AbsaOSS/pramen#599: Refactored the release() method in TokenLockBase.scala, directly related to the synchronization changes in this PR.

Poem

In the warren where files are read and locks are tight,
A bunny tweaks the code, making things just right.
With overwrite in paw and a lock softly released,
Error logs now whisper, and bugs are deceased.
🐇✨
Code hops along—robust, concise, and neat!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2600350 and 560f577.

📒 Files selected for processing (2)
  • pramen/core/src/main/scala/za/co/absa/pramen/core/utils/FsUtils.scala (3 hunks)
  • pramen/core/src/test/scala/za/co/absa/pramen/core/tests/utils/FsUtilsSuite.scala (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pramen/core/src/main/scala/za/co/absa/pramen/core/utils/FsUtils.scala
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Test Spark 3.4.4 on Scala 2.13.16
  • GitHub Check: Test Spark 3.3.4 on Scala 2.13.16
  • GitHub Check: Test Spark 3.5.5 on Scala 2.13.16
  • GitHub Check: Test Spark 3.4.4 on Scala 2.12.20
  • GitHub Check: Test Spark 3.3.4 on Scala 2.12.20
  • GitHub Check: Test Spark 3.5.5 on Scala 2.12.20
  • GitHub Check: Test Spark 2.4.8 on Scala 2.11.12
  • GitHub Check: Test Coverage on Scala 2.12.18
🔇 Additional comments (2)
pramen/core/src/test/scala/za/co/absa/pramen/core/tests/utils/FsUtilsSuite.scala (2)

20-20: LGTM: Import addition is necessary and correct.

The addition of anyBoolean to the Mockito ArgumentMatchers import is required to support the updated mock setup that expects boolean parameters.


327-327: LGTM: Mock setup correctly updated for new method signature.

The mock setup has been properly updated to expect two parameters for the FileSystem.create method, aligning with the enhanced file writing logic that now includes explicit overwrite control. The use of any() and anyBoolean() is appropriate for the Path and overwrite parameters respectively.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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 or {PR 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.

@yruslan yruslan requested a review from Copilot May 30, 2025 14:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates file write behavior by adding an overwrite flag, refines file-reading logic, and corrects token-lock release synchronization to address issues on DBFS.

  • Introduces an overwrite parameter in writeFile and updates its callers
  • Changes readFile to allocate based on actual file size and log read errors
  • Improves TokenLockBase.release and shutdown hook to track prior acquisition before releasing

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
FsUtils.scala Added overwrite flag to writeFile, updated callers, improved readFile
TokenLockBase.scala Refined release and shutdown hook synchronization to respect previous state
JournalHadoopCsv.scala Updated write call to pass overwrite = false
BookkeeperText.scala Updated write call to pass overwrite = false
Comments suppressed due to low confidence (1)

pramen/core/src/main/scala/za/co/absa/pramen/core/utils/FsUtils.scala:322

  • [nitpick] Use StandardCharsets.UTF_8 instead of a string literal to avoid typos and improve readability.
new String(content, "UTF-8")

*/
def writeFile(filePath: Path, content: String): Unit = {
val out = fs.create(filePath)
def writeFile(filePath: Path, content: String, overwrite: Boolean = false): Unit = {

Copilot AI May 30, 2025

Copy link

Choose a reason for hiding this comment

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

Defaulting overwrite to false changes the previous behavior (which always overwrote). Consider setting the default to true or documenting this behavioral change explicitly to avoid unexpected failures.

Suggested change
def writeFile(filePath: Path, content: String, overwrite: Boolean = false): Unit = {
def writeFile(filePath: Path, content: String, overwrite: Boolean = true): Unit = {

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

Comment thread pramen/core/src/main/scala/za/co/absa/pramen/core/utils/FsUtils.scala Outdated
Comment thread pramen/core/src/main/scala/za/co/absa/pramen/core/utils/FsUtils.scala Outdated
Comment thread pramen/core/src/main/scala/za/co/absa/pramen/core/utils/FsUtils.scala Outdated
@github-actions

Copy link
Copy Markdown

Unit Test Coverage

Overall Project 84.91% -0.07% 🍏
Files changed 51.2%

Module Coverage
pramen:core Jacoco Report 85.79% -0.08%
Files
Module File Coverage
pramen:core Jacoco Report TokenLockBase.scala 80.99% -2.92%
FsUtils.scala 80.99% -4.07%

@yruslan yruslan merged commit ec6256d into main May 30, 2025
9 checks passed
@yruslan yruslan deleted the bugfix/hadoopfs-locking-fs-error branch May 30, 2025 15:19
@yruslan yruslan mentioned this pull request Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants