forked from apache/hadoop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CDPD-35180. HADOOP-18091. S3A auditing leaks memory through ThreadLoc…
…al references (apache#3930) Adds a new map type WeakReferenceMap, which stores weak references to values, and a WeakReferenceThreadMap subclass to more closely resemble a thread local type, as it is a map of threadId to value. Construct it with a factory method and optional callback for notification on loss and regeneration. WeakReferenceThreadMap<WrappingAuditSpan> activeSpan = new WeakReferenceThreadMap<>( (k) -> getUnbondedSpan(), this::noteSpanReferenceLost); This is used in ActiveAuditManagerS3A for span tracking. Relates to * HADOOP-17511. Add an Audit plugin point for S3A * HADOOP-18094. Disable S3A auditing by default. Contributed by Steve Loughran. Change-Id: Ibf7bb082fd47298f7ebf46d92f56e80ca9b2aaf8 Conflicts: hadoop-common-project/hadoop-common/src/main/resources/core-default.xml Change-Id: Iaa092c89ab0be16f816b56be78d795ce618a8656
- Loading branch information
1 parent
ec0fccf
commit e21e220
Showing
18 changed files
with
1,355 additions
and
39 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
54 changes: 54 additions & 0 deletions
54
...project/hadoop-common/src/main/java/org/apache/hadoop/fs/impl/WeakReferenceThreadMap.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,54 @@ | ||
/* | ||
* 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.fs.impl; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import javax.annotation.Nullable; | ||
|
||
import org.apache.hadoop.util.WeakReferenceMap; | ||
|
||
/** | ||
* A WeakReferenceMap for threads. | ||
* @param <V> value type of the map | ||
*/ | ||
public class WeakReferenceThreadMap<V> extends WeakReferenceMap<Long, V> { | ||
|
||
public WeakReferenceThreadMap(final Function<? super Long, ? extends V> factory, | ||
@Nullable final Consumer<? super Long> referenceLost) { | ||
super(factory, referenceLost); | ||
} | ||
|
||
public V getForCurrentThread() { | ||
return get(currentThreadId()); | ||
} | ||
|
||
public V removeForCurrentThread() { | ||
return remove(currentThreadId()); | ||
} | ||
|
||
public long currentThreadId() { | ||
return Thread.currentThread().getId(); | ||
} | ||
|
||
public V setForCurrentThread(V newVal) { | ||
return put(currentThreadId(), newVal); | ||
} | ||
|
||
} |
Oops, something went wrong.