Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HDFS-7496. Fix FsVolume removal race conditions on the DataNode by re…
…ference-counting the volume instances (lei via cmccabe)
- Loading branch information
Colin Patrick Mccabe
committed
Jan 21, 2015
1 parent
889ab07
commit b7f4a31
Showing
24 changed files
with
717 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ject/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ReplicaHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hdfs.server.datanode; | ||
|
||
import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeReference; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
|
||
/** | ||
* This class includes a replica being actively written and the reference to | ||
* the fs volume where this replica is located. | ||
*/ | ||
public class ReplicaHandler implements Closeable { | ||
private final ReplicaInPipelineInterface replica; | ||
private final FsVolumeReference volumeReference; | ||
|
||
public ReplicaHandler( | ||
ReplicaInPipelineInterface replica, FsVolumeReference reference) { | ||
this.replica = replica; | ||
this.volumeReference = reference; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
if (this.volumeReference != null) { | ||
volumeReference.close(); | ||
} | ||
} | ||
|
||
public ReplicaInPipelineInterface getReplica() { | ||
return replica; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...dfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/FsVolumeReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hdfs.server.datanode.fsdataset; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
|
||
/** | ||
* This is the interface for holding reference count as AutoClosable resource. | ||
* It increases the reference count by one in the constructor, and decreases | ||
* the reference count by one in {@link #close()}. | ||
* | ||
* <pre> | ||
* {@code | ||
* try (FsVolumeReference ref = volume.obtainReference()) { | ||
* // Do IOs on the volume | ||
* volume.createRwb(...); | ||
* ... | ||
* } | ||
* } | ||
* </pre> | ||
*/ | ||
public interface FsVolumeReference extends Closeable { | ||
/** | ||
* Descrese the reference count of the volume. | ||
* @throws IOException it never throws IOException. | ||
*/ | ||
@Override | ||
public void close() throws IOException; | ||
|
||
/** Returns the underlying volume object */ | ||
public FsVolumeSpi getVolume(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.