|
@@ -89,7 +89,7 @@ import org.apache.hadoop.util.Daemon;
|
|
|
import org.apache.hadoop.util.DataChecksum;
|
|
|
import org.apache.hadoop.util.DiskChecker.DiskErrorException;
|
|
|
import org.apache.hadoop.util.DiskChecker.DiskOutOfSpaceException;
|
|
|
-import org.apache.hadoop.util.InstrumentedLock;
|
|
|
+import org.apache.hadoop.util.InstrumentedReadWriteLock;
|
|
|
import org.apache.hadoop.util.ReflectionUtils;
|
|
|
import org.apache.hadoop.util.Time;
|
|
|
import org.apache.hadoop.util.Timer;
|
|
@@ -125,7 +125,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.Executor;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.locks.Condition;
|
|
|
-import java.util.concurrent.locks.ReentrantLock;
|
|
|
+import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
|
|
|
|
/**************************************************
|
|
|
* FSDataset manages a set of data blocks. Each block
|
|
@@ -179,7 +179,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
|
|
|
@Override
|
|
|
public FsVolumeImpl getVolume(final ExtendedBlock b) {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
final ReplicaInfo r =
|
|
|
volumeMap.get(b.getBlockPoolId(), b.getLocalBlock());
|
|
|
return r != null ? (FsVolumeImpl) r.getVolume() : null;
|
|
@@ -189,7 +189,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
@Override // FsDatasetSpi
|
|
|
public Block getStoredBlock(String bpid, long blkid)
|
|
|
throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
File blockfile = null;
|
|
|
|
|
|
ReplicaInfo info = volumeMap.get(bpid, blkid);
|
|
@@ -210,7 +210,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
public Set<? extends Replica> deepCopyReplica(String bpid)
|
|
|
throws IOException {
|
|
|
Set<? extends Replica> replicas = null;
|
|
|
- try (AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try (AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
replicas = new HashSet<>(volumeMap.replicas(bpid) == null ? Collections.
|
|
|
EMPTY_SET : volumeMap.replicas(bpid));
|
|
|
}
|
|
@@ -250,7 +250,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- try (AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try (AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
final ReplicaInfo replicaInfo = getReplicaInfo(b);
|
|
|
if (replicaInfo != null) {
|
|
|
volume = replicaInfo.getVolume();
|
|
@@ -294,8 +294,12 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
private final int maxDataLength;
|
|
|
|
|
|
@VisibleForTesting
|
|
|
- final AutoCloseableLock datasetLock;
|
|
|
- private final Condition datasetLockCondition;
|
|
|
+ final AutoCloseableLock datasetWriteLock;
|
|
|
+ @VisibleForTesting
|
|
|
+ final AutoCloseableLock datasetReadLock;
|
|
|
+ @VisibleForTesting
|
|
|
+ final InstrumentedReadWriteLock datasetRWLock;
|
|
|
+ private final Condition datasetWriteLockCondition;
|
|
|
|
|
|
/**
|
|
|
* An FSDataset has a directory where it loads its data files.
|
|
@@ -307,15 +311,20 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
this.dataStorage = storage;
|
|
|
this.conf = conf;
|
|
|
this.smallBufferSize = DFSUtilClient.getSmallBufferSize(conf);
|
|
|
- this.datasetLock = new AutoCloseableLock(
|
|
|
- new InstrumentedLock(getClass().getName(), LOG,
|
|
|
- new ReentrantLock(true),
|
|
|
- conf.getTimeDuration(
|
|
|
- DFSConfigKeys.DFS_LOCK_SUPPRESS_WARNING_INTERVAL_KEY,
|
|
|
- DFSConfigKeys.DFS_LOCK_SUPPRESS_WARNING_INTERVAL_DEFAULT,
|
|
|
- TimeUnit.MILLISECONDS),
|
|
|
- 300));
|
|
|
- this.datasetLockCondition = datasetLock.newCondition();
|
|
|
+ this.datasetRWLock = new InstrumentedReadWriteLock(
|
|
|
+ conf.getBoolean(DFSConfigKeys.DFS_DATANODE_LOCK_FAIR_KEY,
|
|
|
+ DFSConfigKeys.DFS_DATANODE_LOCK_FAIR_DEFAULT),
|
|
|
+ "FsDatasetRWLock", LOG, conf.getTimeDuration(
|
|
|
+ DFSConfigKeys.DFS_LOCK_SUPPRESS_WARNING_INTERVAL_KEY,
|
|
|
+ DFSConfigKeys.DFS_LOCK_SUPPRESS_WARNING_INTERVAL_DEFAULT,
|
|
|
+ TimeUnit.MILLISECONDS),
|
|
|
+ conf.getTimeDuration(
|
|
|
+ DFSConfigKeys.DFS_DATANODE_LOCK_REPORTING_THRESHOLD_MS_KEY,
|
|
|
+ DFSConfigKeys.DFS_DATANODE_LOCK_REPORTING_THRESHOLD_MS_DEFAULT,
|
|
|
+ TimeUnit.MILLISECONDS));
|
|
|
+ this.datasetWriteLock = new AutoCloseableLock(datasetRWLock.writeLock());
|
|
|
+ this.datasetReadLock = new AutoCloseableLock(datasetRWLock.readLock());
|
|
|
+ this.datasetWriteLockCondition = datasetWriteLock.newCondition();
|
|
|
|
|
|
// The number of volumes required for operation is the total number
|
|
|
// of volumes minus the number of failed volumes we can tolerate.
|
|
@@ -354,7 +363,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
}
|
|
|
|
|
|
storageMap = new ConcurrentHashMap<String, DatanodeStorage>();
|
|
|
- volumeMap = new ReplicaMap(datasetLock);
|
|
|
+ volumeMap = new ReplicaMap(datasetRWLock);
|
|
|
ramDiskReplicaTracker = RamDiskReplicaTracker.getInstance(conf, this);
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@@ -444,7 +453,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
ReplicaMap replicaMap,
|
|
|
Storage.StorageDirectory sd, StorageType storageType,
|
|
|
FsVolumeReference ref) throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
DatanodeStorage dnStorage = storageMap.get(sd.getStorageUuid());
|
|
|
if (dnStorage != null) {
|
|
|
final String errorMsg = String.format(
|
|
@@ -475,7 +484,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
FsVolumeImpl fsVolume = new FsVolumeImpl(
|
|
|
this, sd.getStorageUuid(), dir, this.conf, storageType);
|
|
|
FsVolumeReference ref = fsVolume.obtainReference();
|
|
|
- ReplicaMap tempVolumeMap = new ReplicaMap(datasetLock);
|
|
|
+ ReplicaMap tempVolumeMap = new ReplicaMap(datasetRWLock);
|
|
|
fsVolume.getVolumeMap(tempVolumeMap, ramDiskReplicaTracker);
|
|
|
|
|
|
activateVolume(tempVolumeMap, sd, storageType, ref);
|
|
@@ -509,7 +518,8 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
StorageType storageType = location.getStorageType();
|
|
|
final FsVolumeImpl fsVolume =
|
|
|
createFsVolume(sd.getStorageUuid(), sd.getCurrentDir(), storageType);
|
|
|
- final ReplicaMap tempVolumeMap = new ReplicaMap(new AutoCloseableLock());
|
|
|
+ final ReplicaMap tempVolumeMap =
|
|
|
+ new ReplicaMap(new ReentrantReadWriteLock());
|
|
|
ArrayList<IOException> exceptions = Lists.newArrayList();
|
|
|
|
|
|
for (final NamespaceInfo nsInfo : nsInfos) {
|
|
@@ -542,7 +552,8 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
|
|
|
/**
|
|
|
* Removes a set of volumes from FsDataset.
|
|
|
- * @param volumesToRemove a set of absolute root path of each volume.
|
|
|
+ * @param storageLocsToRemove a set of
|
|
|
+ * {@link StorageLocation}s for each volume.
|
|
|
* @param clearFailure set true to clear failure information.
|
|
|
*/
|
|
|
@Override
|
|
@@ -558,7 +569,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
|
|
|
Map<String, List<ReplicaInfo>> blkToInvalidate = new HashMap<>();
|
|
|
List<String> storageToRemove = new ArrayList<>();
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
for (int idx = 0; idx < dataStorage.getNumStorageDirs(); idx++) {
|
|
|
Storage.StorageDirectory sd = dataStorage.getStorageDir(idx);
|
|
|
final File absRoot = sd.getRoot().getAbsoluteFile();
|
|
@@ -568,7 +579,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
// Disable the volume from the service.
|
|
|
asyncDiskService.removeVolume(sd.getCurrentDir());
|
|
|
volumes.removeVolume(absRoot, clearFailure);
|
|
|
- volumes.waitVolumeRemoved(5000, datasetLockCondition);
|
|
|
+ volumes.waitVolumeRemoved(5000, datasetWriteLockCondition);
|
|
|
|
|
|
// Removed all replica information for the blocks on the volume.
|
|
|
// Unlike updating the volumeMap in addVolume(), this operation does
|
|
@@ -616,7 +627,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
for(String storageUuid : storageToRemove) {
|
|
|
storageMap.remove(storageUuid);
|
|
|
}
|
|
@@ -814,7 +825,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
public InputStream getBlockInputStream(ExtendedBlock b,
|
|
|
long seekOffset) throws IOException {
|
|
|
ReplicaInfo info;
|
|
|
- try (AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try (AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
info = volumeMap.get(b.getBlockPoolId(), b.getLocalBlock());
|
|
|
}
|
|
|
|
|
@@ -904,7 +915,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
@Override // FsDatasetSpi
|
|
|
public ReplicaInputStreams getTmpInputStreams(ExtendedBlock b,
|
|
|
long blkOffset, long metaOffset) throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
final ReplicaInfo info = getReplicaInfo(b);
|
|
|
final FileIoProvider fileIoProvider = datanode.getFileIoProvider();
|
|
|
FsVolumeReference ref = info.getVolume().obtainReference();
|
|
@@ -1026,7 +1037,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
}
|
|
|
|
|
|
FsVolumeReference volumeRef = null;
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
volumeRef = volumes.getNextVolume(targetStorageType, block.getNumBytes());
|
|
|
}
|
|
|
try {
|
|
@@ -1045,7 +1056,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
newReplicaInfo.setNumBytes(blockFiles[1].length());
|
|
|
// Finalize the copied files
|
|
|
newReplicaInfo = finalizeReplica(block.getBlockPoolId(), newReplicaInfo);
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
// Increment numBlocks here as this block moved without knowing to BPS
|
|
|
FsVolumeImpl volume = (FsVolumeImpl) newReplicaInfo.getVolume();
|
|
|
volume.getBlockPoolSlice(block.getBlockPoolId()).incrNumBlocks();
|
|
@@ -1190,7 +1201,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
@Override // FsDatasetSpi
|
|
|
public ReplicaHandler append(ExtendedBlock b,
|
|
|
long newGS, long expectedBlockLen) throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
// If the block was successfully finalized because all packets
|
|
|
// were successfully processed at the Datanode but the ack for
|
|
|
// some of the packets were not received by the client. The client
|
|
@@ -1242,7 +1253,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
private ReplicaBeingWritten append(String bpid,
|
|
|
FinalizedReplica replicaInfo, long newGS, long estimateBlockLen)
|
|
|
throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
// If the block is cached, start uncaching it.
|
|
|
cacheManager.uncacheBlock(bpid, replicaInfo.getBlockId());
|
|
|
|
|
@@ -1378,7 +1389,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
|
|
|
while (true) {
|
|
|
try {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
ReplicaInfo replicaInfo = recoverCheck(b, newGS, expectedBlockLen);
|
|
|
|
|
|
FsVolumeReference ref = replicaInfo.getVolume().obtainReference();
|
|
@@ -1410,7 +1421,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
LOG.info("Recover failed close " + b);
|
|
|
while (true) {
|
|
|
try {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
// check replica's state
|
|
|
ReplicaInfo replicaInfo = recoverCheck(b, newGS, expectedBlockLen);
|
|
|
// bump the replica's GS
|
|
@@ -1461,7 +1472,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
public ReplicaHandler createRbw(
|
|
|
StorageType storageType, ExtendedBlock b, boolean allowLazyPersist)
|
|
|
throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
ReplicaInfo replicaInfo = volumeMap.get(b.getBlockPoolId(),
|
|
|
b.getBlockId());
|
|
|
if (replicaInfo != null) {
|
|
@@ -1527,7 +1538,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
|
|
|
while (true) {
|
|
|
try {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
ReplicaInfo replicaInfo = getReplicaInfo(b.getBlockPoolId(), b.getBlockId());
|
|
|
|
|
|
// check the replica's state
|
|
@@ -1551,7 +1562,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
private ReplicaHandler recoverRbwImpl(ReplicaBeingWritten rbw,
|
|
|
ExtendedBlock b, long newGS, long minBytesRcvd, long maxBytesRcvd)
|
|
|
throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
// check generation stamp
|
|
|
long replicaGenerationStamp = rbw.getGenerationStamp();
|
|
|
if (replicaGenerationStamp < b.getGenerationStamp() ||
|
|
@@ -1613,7 +1624,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
@Override // FsDatasetSpi
|
|
|
public ReplicaInPipeline convertTemporaryToRbw(
|
|
|
final ExtendedBlock b) throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
final long blockId = b.getBlockId();
|
|
|
final long expectedGs = b.getGenerationStamp();
|
|
|
final long visible = b.getNumBytes();
|
|
@@ -1687,7 +1698,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
ReplicaInfo lastFoundReplicaInfo = null;
|
|
|
boolean isInPipeline = false;
|
|
|
do {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
ReplicaInfo currentReplicaInfo =
|
|
|
volumeMap.get(b.getBlockPoolId(), b.getBlockId());
|
|
|
if (currentReplicaInfo == lastFoundReplicaInfo) {
|
|
@@ -1733,7 +1744,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
invalidate(b.getBlockPoolId(), new Block[] { lastFoundReplicaInfo },
|
|
|
false);
|
|
|
}
|
|
|
- try (AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try (AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
FsVolumeReference ref = volumes.getNextVolume(storageType, b
|
|
|
.getNumBytes());
|
|
|
FsVolumeImpl v = (FsVolumeImpl) ref.getVolume();
|
|
@@ -1787,7 +1798,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
throws IOException {
|
|
|
ReplicaInfo replicaInfo = null;
|
|
|
ReplicaInfo finalizedReplicaInfo = null;
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
if (Thread.interrupted()) {
|
|
|
// Don't allow data modifications from interrupted threads
|
|
|
throw new IOException("Cannot finalize block from Interrupted Thread");
|
|
@@ -1817,7 +1828,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
|
|
|
private FinalizedReplica finalizeReplica(String bpid, ReplicaInfo replicaInfo)
|
|
|
throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
FinalizedReplica newReplicaInfo = null;
|
|
|
if (replicaInfo.getState() == ReplicaState.RUR &&
|
|
|
((ReplicaUnderRecovery) replicaInfo).getOriginalReplica().getState()
|
|
@@ -1871,7 +1882,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
*/
|
|
|
@Override // FsDatasetSpi
|
|
|
public void unfinalizeBlock(ExtendedBlock b) throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
ReplicaInfo replicaInfo = volumeMap.get(b.getBlockPoolId(),
|
|
|
b.getLocalBlock());
|
|
|
if (replicaInfo != null
|
|
@@ -1926,7 +1937,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
new HashMap<String, BlockListAsLongs.Builder>();
|
|
|
|
|
|
List<FsVolumeImpl> curVolumes = null;
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
curVolumes = volumes.getVolumes();
|
|
|
for (FsVolumeSpi v : curVolumes) {
|
|
|
builders.put(v.getStorageID(), BlockListAsLongs.builder(maxDataLength));
|
|
@@ -1983,7 +1994,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
* Gets a list of references to the finalized blocks for the given block pool.
|
|
|
* <p>
|
|
|
* Callers of this function should call
|
|
|
- * {@link FsDatasetSpi#acquireDatasetLock} to avoid blocks' status being
|
|
|
+ * {@link FsDatasetSpi#acquireDatasetLock()} to avoid blocks' status being
|
|
|
* changed during list iteration.
|
|
|
* </p>
|
|
|
* @return a list of references to the finalized blocks for the given block
|
|
@@ -1991,7 +2002,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
*/
|
|
|
@Override
|
|
|
public List<FinalizedReplica> getFinalizedBlocks(String bpid) {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
final ArrayList<FinalizedReplica> finalized =
|
|
|
new ArrayList<FinalizedReplica>(volumeMap.size(bpid));
|
|
|
for (ReplicaInfo b : volumeMap.replicas(bpid)) {
|
|
@@ -2077,7 +2088,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
//Should we check for metadata file too?
|
|
|
File f = null;
|
|
|
ReplicaInfo info;
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
info = volumeMap.get(bpid, blockId);
|
|
|
if (info != null) {
|
|
|
f = info.getBlockFile();
|
|
@@ -2135,7 +2146,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
for (int i = 0; i < invalidBlks.length; i++) {
|
|
|
final File f;
|
|
|
final FsVolumeImpl v;
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
final ReplicaInfo info = volumeMap.get(bpid, invalidBlks[i]);
|
|
|
if (info == null) {
|
|
|
ReplicaInfo infoByBlockId =
|
|
@@ -2258,7 +2269,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
long length, genstamp;
|
|
|
Executor volumeExecutor;
|
|
|
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
ReplicaInfo info = volumeMap.get(bpid, blockId);
|
|
|
boolean success = false;
|
|
|
try {
|
|
@@ -2326,7 +2337,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
|
|
|
@Override // FsDatasetSpi
|
|
|
public boolean contains(final ExtendedBlock block) {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
final long blockId = block.getLocalBlock().getBlockId();
|
|
|
return getFile(block.getBlockPoolId(), blockId, false) != null;
|
|
|
}
|
|
@@ -2456,7 +2467,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
File diskMetaFile, FsVolumeSpi vol) throws IOException {
|
|
|
Block corruptBlock = null;
|
|
|
ReplicaInfo memBlockInfo;
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
memBlockInfo = volumeMap.get(bpid, blockId);
|
|
|
if (memBlockInfo != null && memBlockInfo.getState() != ReplicaState.FINALIZED) {
|
|
|
// Block is not finalized - ignore the difference
|
|
@@ -2621,7 +2632,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
|
|
|
@Override
|
|
|
public String getReplicaString(String bpid, long blockId) {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
final Replica r = volumeMap.get(bpid, blockId);
|
|
|
return r == null ? "null" : r.toString();
|
|
|
}
|
|
@@ -2726,7 +2737,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
final long recoveryId,
|
|
|
final long newBlockId,
|
|
|
final long newlength) throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
//get replica
|
|
|
final String bpid = oldBlock.getBlockPoolId();
|
|
|
final ReplicaInfo replica = volumeMap.get(bpid, oldBlock.getBlockId());
|
|
@@ -2868,7 +2879,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
@Override // FsDatasetSpi
|
|
|
public long getReplicaVisibleLength(final ExtendedBlock block)
|
|
|
throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
final Replica replica = getReplicaInfo(block.getBlockPoolId(),
|
|
|
block.getBlockId());
|
|
|
if (replica.getGenerationStamp() < block.getGenerationStamp()) {
|
|
@@ -2884,7 +2895,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
public void addBlockPool(String bpid, Configuration conf)
|
|
|
throws IOException {
|
|
|
LOG.info("Adding block pool " + bpid);
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
volumes.addBlockPool(bpid, conf);
|
|
|
volumeMap.initBlockPool(bpid);
|
|
|
}
|
|
@@ -2893,7 +2904,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
|
|
|
@Override
|
|
|
public void shutdownBlockPool(String bpid) {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
LOG.info("Removing block pool " + bpid);
|
|
|
Map<DatanodeStorage, BlockListAsLongs> blocksPerVolume =
|
|
|
getBlockReports(bpid);
|
|
@@ -2967,7 +2978,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
@Override //FsDatasetSpi
|
|
|
public void deleteBlockPool(String bpid, boolean force)
|
|
|
throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
List<FsVolumeImpl> curVolumes = volumes.getVolumes();
|
|
|
if (!force) {
|
|
|
for (FsVolumeImpl volume : curVolumes) {
|
|
@@ -2996,7 +3007,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
@Override // FsDatasetSpi
|
|
|
public BlockLocalPathInfo getBlockLocalPathInfo(ExtendedBlock block)
|
|
|
throws IOException {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
final Replica replica = volumeMap.get(block.getBlockPoolId(),
|
|
|
block.getBlockId());
|
|
|
if (replica == null) {
|
|
@@ -3089,7 +3100,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
@Override
|
|
|
public void onCompleteLazyPersist(String bpId, long blockId,
|
|
|
long creationTime, File[] savedFiles, FsVolumeImpl targetVolume) {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
ramDiskReplicaTracker.recordEndLazyPersist(bpId, blockId, savedFiles);
|
|
|
|
|
|
targetVolume.incDfsUsedAndNumBlocks(bpId, savedFiles[0].length()
|
|
@@ -3223,7 +3234,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
try {
|
|
|
block = ramDiskReplicaTracker.dequeueNextReplicaToPersist();
|
|
|
if (block != null) {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
replicaInfo = volumeMap.get(block.getBlockPoolId(), block.getBlockId());
|
|
|
|
|
|
// If replicaInfo is null, the block was either deleted before
|
|
@@ -3293,7 +3304,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
long blockFileUsed, metaFileUsed;
|
|
|
final String bpid = replicaState.getBlockPoolId();
|
|
|
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
replicaInfo = getReplicaInfo(replicaState.getBlockPoolId(),
|
|
|
replicaState.getBlockId());
|
|
|
Preconditions.checkState(replicaInfo.getVolume().isTransientStorage());
|
|
@@ -3405,7 +3416,12 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
|
|
|
@Override
|
|
|
public AutoCloseableLock acquireDatasetLock() {
|
|
|
- return datasetLock.acquire();
|
|
|
+ return datasetWriteLock.acquire();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AutoCloseableLock acquireDatasetReadLock() {
|
|
|
+ return datasetReadLock.acquire();
|
|
|
}
|
|
|
|
|
|
public void removeDeletedBlocks(String bpid, Set<Long> blockIds) {
|
|
@@ -3495,7 +3511,7 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
|
|
}
|
|
|
|
|
|
void stopAllDataxceiverThreads(FsVolumeImpl volume) {
|
|
|
- try(AutoCloseableLock lock = datasetLock.acquire()) {
|
|
|
+ try(AutoCloseableLock lock = datasetWriteLock.acquire()) {
|
|
|
for (String blockPoolId : volumeMap.getBlockPoolList()) {
|
|
|
Collection<ReplicaInfo> replicas = volumeMap.replicas(blockPoolId);
|
|
|
for (ReplicaInfo replicaInfo : replicas) {
|