-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix folderManager NPE issue in WALNode when starting iotdb in a disk-full state #16869
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,20 +34,21 @@ | |
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| public abstract class AbstractNodeAllocationStrategy implements NodeAllocationStrategy { | ||
| private static final Logger logger = | ||
| LoggerFactory.getLogger(AbstractNodeAllocationStrategy.class); | ||
| private static final CommonConfig commonConfig = CommonDescriptor.getInstance().getConfig(); | ||
|
|
||
| // manage wal folders | ||
| protected FolderManager folderManager; | ||
| protected AtomicReference<FolderManager> folderManager = new AtomicReference<>(); | ||
|
|
||
| protected AbstractNodeAllocationStrategy() { | ||
| try { | ||
| folderManager = | ||
| folderManager.set( | ||
| new FolderManager( | ||
| Arrays.asList(commonConfig.getWalDirs()), DirectoryStrategyType.SEQUENCE_STRATEGY); | ||
| Arrays.asList(commonConfig.getWalDirs()), DirectoryStrategyType.SEQUENCE_STRATEGY)); | ||
| } catch (DiskSpaceInsufficientException e) { | ||
| logger.error( | ||
| "Fail to create wal node allocation strategy because all disks of wal folders are full.", | ||
|
|
@@ -57,8 +58,16 @@ protected AbstractNodeAllocationStrategy() { | |
|
|
||
| protected IWALNode createWALNode(String identifier) { | ||
| try { | ||
| return folderManager.getNextWithRetry( | ||
| folder -> new WALNode(identifier, folder + File.separator + identifier)); | ||
| // already in lock, so no need to synchronized | ||
| if (folderManager.get() == null) { | ||
| folderManager.set( | ||
| new FolderManager( | ||
| Arrays.asList(commonConfig.getWalDirs()), DirectoryStrategyType.SEQUENCE_STRATEGY)); | ||
| } | ||
|
Comment on lines
+62
to
+66
|
||
| return folderManager | ||
| .get() | ||
| .getNextWithRetry( | ||
| folder -> new WALNode(identifier, folder + File.separator + identifier)); | ||
|
Comment on lines
+67
to
+70
|
||
| } catch (DiskSpaceInsufficientException e) { | ||
| logger.error("Fail to create wal node because all disks of wal folders are full.", e); | ||
| return WALFakeNode.getFailureInstance(e); | ||
|
|
||
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.
Race condition: Multiple threads can simultaneously check
folderManager.get() == nulland proceed to create multiple FolderManager instances. The comment on line 61 states "already in lock, so no need to synchronized", but AtomicReference alone doesn't prevent this race condition. The check-then-set pattern is not atomic. Consider using synchronized double-checked locking:Alternatively, use
compareAndSet()for atomic updates.