HDFS-16233. Do not use exception handler to implement copy-on-write for EnumCounters. (#3468)

(cherry picked from commit 87632bbacf)
(cherry picked from commit bb08de559a)
(cherry picked from commit 978ec57445)
This commit is contained in:
Wei-Chiu Chuang 2021-09-24 23:35:23 +08:00 committed by Akira Ajisaka
parent 9b016b401a
commit 6ef0b3fc21
No known key found for this signature in database
GPG Key ID: C1EDBB9CA400FD50
1 changed files with 2 additions and 7 deletions

View File

@ -23,7 +23,6 @@ import org.apache.hadoop.fs.StorageType;
import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.util.ConstEnumCounters; import org.apache.hadoop.hdfs.util.ConstEnumCounters;
import org.apache.hadoop.hdfs.util.EnumCounters; import org.apache.hadoop.hdfs.util.EnumCounters;
import org.apache.hadoop.hdfs.util.ConstEnumCounters.ConstEnumException;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -57,14 +56,10 @@ public class QuotaCounts {
*/ */
static <T extends Enum<T>> EnumCounters<T> modify(EnumCounters<T> counter, static <T extends Enum<T>> EnumCounters<T> modify(EnumCounters<T> counter,
Consumer<EnumCounters<T>> action) { Consumer<EnumCounters<T>> action) {
try { if (counter instanceof ConstEnumCounters) {
action.accept(counter);
} catch (ConstEnumException cee) {
// We don't call clone here because ConstEnumCounters.clone() will return
// an object of class ConstEnumCounters. We want EnumCounters.
counter = counter.deepCopyEnumCounter(); counter = counter.deepCopyEnumCounter();
action.accept(counter);
} }
action.accept(counter);
return counter; return counter;
} }