Skip to content

Commit

Permalink
ORC-1601: Reduce get HadoopShims sync block in HadoopShimsFactory
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
Improve calling efficiency of `org.apache.orc.impl.HadoopShimsFactory#get`.

### Why are the changes needed?
`org.apache.orc.impl.HadoopShimsFactory#get` is a static method with synchronized. It needs to be locked every time it is called. This is unnecessary.

### How was this patch tested?
GA

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #1769 from cxzl25/ORC-1601.

Authored-by: sychen <sychen@ctrip.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 8f22732)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
  • Loading branch information
cxzl25 authored and dongjoon-hyun committed Jan 22, 2024
1 parent ecfd17a commit 987ccc1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions java/core/src/java/org/apache/orc/impl/HadoopShimsFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class HadoopShimsFactory {

private static final String CURRENT_SHIM_NAME =
"org.apache.orc.impl.HadoopShimsCurrent";
private static HadoopShims SHIMS = null;
private static volatile HadoopShims SHIMS = null;

private static HadoopShims createShimByName(String name) {
try {
Expand All @@ -46,15 +46,19 @@ private static HadoopShims createShimByName(String name) {
}
}

public static synchronized HadoopShims get() {
public static HadoopShims get() {
if (SHIMS == null) {
String[] versionParts = VersionInfo.getVersion().split("[.]");
int major = Integer.parseInt(versionParts[0]);
int minor = Integer.parseInt(versionParts[1]);
if (major < 2 || (major == 2 && minor < 7)) {
LOG.warn("Hadoop " + VersionInfo.getVersion() + " support is dropped.");
synchronized (HadoopShimsFactory.class) {
if (SHIMS == null) {
String[] versionParts = VersionInfo.getVersion().split("[.]");
int major = Integer.parseInt(versionParts[0]);
int minor = Integer.parseInt(versionParts[1]);
if (major < 2 || (major == 2 && minor < 7)) {
LOG.warn("Hadoop " + VersionInfo.getVersion() + " support is dropped.");
}
SHIMS = createShimByName(CURRENT_SHIM_NAME);
}
}
SHIMS = createShimByName(CURRENT_SHIM_NAME);
}
return SHIMS;
}
Expand Down

0 comments on commit 987ccc1

Please sign in to comment.