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 the bug of Worker report 0 size of block replica to master when highly concurrent access #18720

Open
wants to merge 1 commit into
base: master-2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,26 @@ public Optional<TempBlockMeta> getTempBlockMeta(long blockId) {
return Optional.empty();
}


/**
* Gets the metadata of a temp block.
*
* @param sessionId the sessionId of the temp block
* @param blockId the id of the temp block
* @return metadata of the block
*/
public Optional<TempBlockMeta> getTempBlockMeta(long sessionId, long blockId) {
for (StorageTier tier : mTiers) {
for (StorageDir dir : tier.getStorageDirs()) {
Optional<TempBlockMeta> tempBlockMeta = dir.getTempBlockMeta(blockId);
if (tempBlockMeta.isPresent() && tempBlockMeta.get().getSessionId() == sessionId) {
return tempBlockMeta;
}
}
}
return Optional.empty();
}

/**
* Gets the {@link StorageTier} given its tierAlias. Throws an {@link IllegalArgumentException} if
* the tierAlias is not found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,10 @@ public void registerBlockStoreEventListener(BlockStoreEventListener listener) {
private TempBlockMeta checkAndGetTempBlockMeta(long sessionId, long blockId) {
Optional<TempBlockMeta> tempBlockMeta;
try (LockResource r = new LockResource(mMetadataReadLock)) {
tempBlockMeta = mMetaManager.getTempBlockMeta(blockId);
tempBlockMeta = mMetaManager.getTempBlockMeta(sessionId, blockId);
}
checkState(tempBlockMeta.isPresent(),
ExceptionMessage.TEMP_BLOCK_META_NOT_FOUND.getMessage(blockId));
checkState(tempBlockMeta.get().getSessionId() == sessionId,
ExceptionMessage.BLOCK_ID_FOR_DIFFERENT_SESSION.getMessage(blockId,
tempBlockMeta.get().getSessionId(), sessionId));
return tempBlockMeta.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import alluxio.util.IdUtils;
import alluxio.worker.block.io.BlockReader;
import alluxio.worker.block.io.BlockWriter;
import alluxio.worker.block.meta.TempBlockMeta;
import alluxio.worker.block.meta.UnderFileSystemBlockMeta;

import com.codahale.metrics.Counter;
Expand Down Expand Up @@ -346,11 +347,12 @@ private void updateBlockWriter(long offset) throws IOException {
if (mBlockWriter != null && offset > mBlockWriter.getPosition()) {
cancelBlockWriter();
}
TempBlockMeta tempBlockMeta = null;
try {
if (mBlockWriter == null && offset == 0 && !mBlockMeta.isNoCache()) {
BlockStoreLocation loc = BlockStoreLocation.anyDirInTier(
WORKER_STORAGE_TIER_ASSOC.getAlias(0));
mLocalBlockStore.createBlock(mBlockMeta.getSessionId(), mBlockMeta.getBlockId(),
tempBlockMeta = mLocalBlockStore.createBlock(mBlockMeta.getSessionId(), mBlockMeta.getBlockId(),
AllocateOptions.forCreate(mInitialBlockSize, loc));
mBlockWriter = mLocalBlockStore.createBlockWriter(
mBlockMeta.getSessionId(), mBlockMeta.getBlockId());
Expand All @@ -360,13 +362,19 @@ private void updateBlockWriter(long offset) throws IOException {
"Failed to update block writer for UFS block [blockId: {}, ufsPath: {}, offset: {}]: {}",
mBlockMeta.getBlockId(), mBlockMeta.getUnderFileSystemPath(), offset, e.toString());
mBlockWriter = null;
if (tempBlockMeta != null) {
mLocalBlockStore.abortBlock(tempBlockMeta.getSessionId(), tempBlockMeta.getBlockId());
}
} catch (IllegalStateException e) {
// This can happen when there are concurrent UFS readers who are all trying to cache to block.
LOG.debug(
"Failed to update block writer for UFS block [blockId: {}, ufsPath: {}, offset: {}]."
+ "Concurrent UFS readers may be caching the same block.",
mBlockMeta.getBlockId(), mBlockMeta.getUnderFileSystemPath(), offset, e);
mBlockWriter = null;
if (tempBlockMeta != null) {
mLocalBlockStore.abortBlock(tempBlockMeta.getSessionId(), tempBlockMeta.getBlockId());
}
}
}
}
1 change: 1 addition & 0 deletions libexec/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION=308-SNAPSHOT