Skip to content

[FLINK-37689] Improve the comments and variable names for TaskMailbox #26469

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

beliefer
Copy link
Contributor

What is the purpose of the change

This PR aims to improve the comments and variable names for TaskMailbox.
There are some improvement points show below.

  • message -> mail. mail is a more suitable name in the context of TaskMailbox.

  • Adds comments to increasing the readability of tryTake and take. These comments show below.
    Note that the priority is given to retrieving email from the head of batch, and when email cannot be retrieved from the batch, it is retrieved from the head of queue. This also means that emails in batch are older than emails in queue.

  • Supplement the missing exception into comments.

  • The default batch is empty. -> By default, the batch is empty.. The latter is more accurate.

  • (head of queue) -> (head of batch). We only fetch the head mail from the batch not the queue with tryTakeFromBatch.

  • head -> headEmail. The latter is a better variable name. Some code uses headEmail and other uses head before this PR. We should unify the name.

  • Move the size() in TaskMailboxImpl so that it follows the order of the declaration in the interface TaskMailbox.

Brief change log

Improve the comments and variable names for TaskMailbox.

Verifying this change

This change is a trivial rework / code cleanup without any test coverage.

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

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (no)
  • The serializers: (no)
  • The runtime per-record code paths (performance sensitive): (no)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
  • The S3 file system connector: (no)

Documentation

  • Does this pull request introduce a new feature? (no)

@@ -75,7 +75,7 @@ public interface TaskMailbox {
int MIN_PRIORITY = -1;

/**
* The maximal priority for mails. This priority indicates that the message should be performed
* The maximal priority for mails. This priority indicates that the mail should be performed
Copy link
Contributor Author

Choose a reason for hiding this comment

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

message -> mail. mail is a more suitable name in the context of TaskMailbox.

* Returns an optional with either the oldest mail from the mailbox if the mailbox is not empty
* or an empty optional otherwise. Note that the priority is given to retrieving email from the
* head of batch, and when email cannot be retrieved from the batch, it is retrieved from the
* head of queue. This also means that emails in batch are older than emails in queue.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adds comments to increasing the readability of tryTake and take. These comments show below.
Note that the priority is given to retrieving email from the head of batch, and when email cannot be retrieved from the batch, it is retrieved from the head of queue. This also means that emails in batch are older than emails in queue.

*
* <p>Must be called from the mailbox thread ({@link #isMailboxThread()}.
*
* @return an optional with either the oldest mail from the mailbox (head of queue) if the
* mailbox is not empty or an empty optional otherwise.
* @throws IllegalStateException if mailbox is already closed.
* @throws MailboxClosedException if mailbox is already closed.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Supplement the missing exception into comments.

@@ -128,7 +134,7 @@ public interface TaskMailbox {
* not affect {@link #tryTake(int)} and {@link #take(int)}; that is, they return the same mails
* even if no batch had been created.
*
* <p>The default batch is empty. Thus, this method must be invoked once before {@link
* <p>By default, the batch is empty. Thus, this method must be invoked once before {@link
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default batch is empty. -> By default, the batch is empty.. The latter is more accurate.

*/
boolean createBatch();

/**
* Returns an optional with either the oldest mail from the batch (head of queue) if the batch
* Returns an optional with either the oldest mail from the batch (head of batch) if the batch
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(head of queue) -> (head of batch). We only fetch the head mail from the batch not the queue with tryTakeFromBatch.

lock.unlock();
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move the size() in TaskMailboxImpl so that it follows the order of the declaration in the interface TaskMailbox.

return Optional.of(head);
Mail headEmail = takeOrNull(batch, priority);
if (headEmail != null) {
return Optional.of(headEmail);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

head -> headEmail. The latter is a better variable name. Some code uses headEmail and other uses head before this PR. We should unify the name.

@flinkbot
Copy link
Collaborator

flinkbot commented Apr 16, 2025

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@beliefer
Copy link
Contributor Author

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