-
Notifications
You must be signed in to change notification settings - Fork 235
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
feat(wal): optimize the start-up and shutdown of WAL #1625
base: main
Are you sure you want to change the base?
Conversation
@superhx @Chillax-0v0 hey, PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @CLFutureX,
I apologize for the delay in reviewing this PR. Thank you for your patience and for the effort you've put into this work.
I've gone through the changes and have a few suggestions that I believe will improve the implementation. Could you please consider these modifications?
Thank you again for your contribution!
switch (WAL_STATE.get(this)) { | ||
case WAL_STATE_INIT: | ||
if (WAL_STATE.compareAndSet(this, WAL_STATE_INIT, WAL_STATE_STARTED)) { | ||
boolean success = false; | ||
try { | ||
doStart(); | ||
success = true; | ||
} finally { | ||
if (!success) { | ||
WAL_STATE.compareAndSet(this, WAL_STATE_STARTED, WAL_STATE_INIT); | ||
LOGGER.warn("block WAL service started fail"); | ||
} | ||
} | ||
} | ||
break; | ||
case WAL_STATE_STARTED: | ||
LOGGER.warn("block WAL service already started"); | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the "started" state is primarily used to check whether the metadata required for WAL operation (e.g., WAL Header) is ready (see callers of checkStarted
), in order to avoid data corruption caused by premature writes.
Therefore, the state can only be set to "started" after the doStart
method executes successfully.
Adding an intermediate "starting" state might resolve the issue.
private static final int WAL_STATE_STARTED = 2; | ||
private static final int WAL_STATE_SHUTING_DOWN = 3; | ||
private static final int WAL_STATE_SHUTDOWN = 4; | ||
private static final AtomicIntegerFieldUpdater<BlockWALService> WAL_STATE = AtomicIntegerFieldUpdater.newUpdater(BlockWALService.class, "state"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is no need to use AtomicIntegerFieldUpdater
here; an AtomicReference<State>
should suffice. Here are a few reasons:
- In our scenario, there won't be many
WAL
instances simultaneously (in fact, in most cases, there is only one). So a globalstatic
updater is unnecessary. - Compared to
AtomicIntegerFieldUpdater
,AtomicReference
can provide better code readability and maintainability. - I conducted a simple benchmark, and there is no significant performance difference between them (in fact, for the most frequently called
get
method in our use case,AtomicReference
performs slightly better).
private static final int WAL_STATE_INIT = 1; | ||
private static final int WAL_STATE_STARTED = 2; | ||
private static final int WAL_STATE_SHUTING_DOWN = 3; | ||
private static final int WAL_STATE_SHUTDOWN = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use AtomicReference
to maintain the state of WAL
(as I mentioned above), then these int
constants can also be replaced with a separate enum class.
# Conflicts: # s3stream/src/main/java/com/automq/stream/s3/wal/impl/block/BlockWALService.java
Thank you for your reply, I am very willing to make the modifications according to your suggestions.
Thank you for your reply. I am happy to modify according to your suggestions: Firstly, I plan to create a new WalState enum and the corresponding AtomicReference object as advised enum WalState { However, during the modification process, I found that the state branch judgment in the start() method is not very Secondly, a starting state has been added to the state machine. The state is only changed to started after a successful startup. |
Signed-off-by: Ning Yu <[email protected]>
@CLFutureX Hello, I have submitted a PR to your branch CLFutureX#1, which converts |
refactor(s3stream/wal): use an enum class to identify the WAL state
LGTM |
This PR is being marked as stale since it has not had any activity in 90 days. If you would like to keep this PR alive, please ask a committer for review. If the PR has merge conflicts, please update it with the latest from trunk (or appropriate release branch) If this PR is no longer valid or desired, please feel free to close it. If no activity occurs in the next 30 days, it will be automatically closed. |
Motivation :
As a core component of AutoMQ that is closely related to memory resources, the initialization and termination processes of WAL must ensure a high degree of robustness. However, there are currently some flaws in these processes that fail to achieve a complete operational loop. This means that during the startup and shutdown processes, all relevant resources may not be properly handled, which can affect the stability and reliability of the system. It is necessary to further optimize these processes to ensure they can manage memory resources seamlessly from start to finish, avoiding potential resource leaks or other issues.