Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.util;

import java.io.IOException;

/**
* This presents a block of code with a possibility of throwing an IOException.
*/
@FunctionalInterface
public interface CheckedRunnable<E extends IOException> {
void run() throws E;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.util;

import java.io.IOException;

/**
* Similar to {@link java.util.function.Supplier}, this class presents a block
* of code generating a value with a possibility of throwing an IOException.
*/
@FunctionalInterface
public interface CheckedSupplier<T, E extends IOException> {
T get() throws E;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.util;

import org.apache.hadoop.metrics2.lib.MutableRate;

import java.io.IOException;

/**
* Encloses helpers to deal with metrics.
*/
public final class MetricUtil {
private MetricUtil() {
}

public static <T, E extends IOException> T captureLatencyNs(
MutableRate metric,
CheckedSupplier<T, E> block) throws E {
long start = Time.monotonicNowNanos();
try {
return block.get();
} finally {
metric.add(Time.monotonicNowNanos() - start);
}
}

public static <E extends IOException> void captureLatencyNs(
MutableRate metric,
CheckedRunnable<E> block) throws IOException {
long start = Time.monotonicNowNanos();
try {
block.run();
} finally {
metric.add(Time.monotonicNowNanos() - start);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void fetchBlocks() throws IOException {
OmKeyArgs keyArgs =
new OmKeyArgs.Builder().setVolumeName(volume.getName())
.setBucketName(bucket.getName()).setKeyName(keyName)
.setRefreshPipeline(true).setSortDatanodesInPipeline(true)
.setSortDatanodesInPipeline(true)
.setLatestVersionLocation(true).build();
keyInfo = ozoneManagerClient.lookupKey(keyArgs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,6 @@ public OzoneInputStream getKey(
.setVolumeName(volumeName)
.setBucketName(bucketName)
.setKeyName(keyName)
.setRefreshPipeline(true)
.setSortDatanodesInPipeline(topologyAwareReadEnabled)
.setLatestVersionLocation(getLatestVersionLocation)
.build();
Expand All @@ -1266,7 +1265,6 @@ public OzoneInputStream getKey(
.setVolumeName(volumeName)
.setBucketName(bucketName)
.setKeyName(keyName)
.setRefreshPipeline(true)
.setSortDatanodesInPipeline(topologyAwareReadEnabled)
.build();

Expand Down Expand Up @@ -1412,7 +1410,6 @@ public OzoneKeyDetails getKeyDetails(
.setVolumeName(volumeName)
.setBucketName(bucketName)
.setKeyName(keyName)
.setRefreshPipeline(true)
.setSortDatanodesInPipeline(topologyAwareReadEnabled)
.setLatestVersionLocation(getLatestVersionLocation)
.build();
Expand Down Expand Up @@ -1644,7 +1641,6 @@ public OzoneFileStatus getOzoneFileStatus(String volumeName,
.setVolumeName(volumeName)
.setBucketName(bucketName)
.setKeyName(keyName)
.setRefreshPipeline(true)
.setSortDatanodesInPipeline(topologyAwareReadEnabled)
.setLatestVersionLocation(getLatestVersionLocation)
.build();
Expand Down Expand Up @@ -1702,7 +1698,6 @@ private OzoneInputStream getInputStreamWithRetryFunction(
.setVolumeName(omKeyInfo.getVolumeName())
.setBucketName(omKeyInfo.getBucketName())
.setKeyName(omKeyInfo.getKeyName())
.setRefreshPipeline(true)
.setSortDatanodesInPipeline(topologyAwareReadEnabled)
.setLatestVersionLocation(getLatestVersionLocation)
.build();
Expand Down Expand Up @@ -1747,7 +1742,6 @@ private OmKeyArgs prepareOmKeyArgs(String volumeName, String bucketName,
.setVolumeName(volumeName)
.setBucketName(bucketName)
.setKeyName(keyName)
.setRefreshPipeline(true)
.setSortDatanodesInPipeline(topologyAwareReadEnabled)
.setLatestVersionLocation(getLatestVersionLocation)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ public static boolean isReadOnly(
// write to OM DB. And therefore it doesn't need a OMClientRequest.
// Although indirectly the Ranger sync service task could invoke write
// operation SetRangerServiceVersion.
case GetKeyInfo:
return true;
case CreateVolume:
case SetVolumeProperty:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* 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.ozone.om.helpers;

import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetKeyInfoResponse;

import java.io.IOException;
import java.util.Optional;

/**
* Encloses a {@link OmKeyInfo} and optionally a volume context.
*/
public class KeyInfoWithVolumeContext {
/**
* Volume arguments.
*/
private final Optional<OmVolumeArgs> volumeArgs;

/**
* To be used for client-side operations involving KMS like getDEK().
*/
private final Optional<String> userPrincipal;

private final OmKeyInfo keyInfo;

public KeyInfoWithVolumeContext(OmVolumeArgs volumeArgs,
String userPrincipal,
OmKeyInfo keyInfo) {
this.volumeArgs = Optional.ofNullable(volumeArgs);
this.userPrincipal = Optional.ofNullable(userPrincipal);
this.keyInfo = keyInfo;
}

public static KeyInfoWithVolumeContext fromProtobuf(
GetKeyInfoResponse proto) throws IOException {
return newBuilder()
.setVolumeArgs(proto.hasVolumeInfo() ?
OmVolumeArgs.getFromProtobuf(proto.getVolumeInfo()) : null)
.setUserPrincipal(proto.getUserPrincipal())
.setKeyInfo(OmKeyInfo.getFromProtobuf(proto.getKeyInfo()))
.build();
}

public GetKeyInfoResponse toProtobuf(int clientVersion) {
GetKeyInfoResponse.Builder builder = GetKeyInfoResponse.newBuilder();
volumeArgs.ifPresent(v -> builder.setVolumeInfo(v.getProtobuf()));
userPrincipal.ifPresent(builder::setUserPrincipal);
builder.setKeyInfo(keyInfo.getProtobuf(clientVersion));
return builder.build();
}

public OmKeyInfo getKeyInfo() {
return keyInfo;
}

public Optional<OmVolumeArgs> getVolumeArgs() {
return volumeArgs;
}

public Optional<String> getUserPrincipal() {
return userPrincipal;
}

public static Builder newBuilder() {
return new Builder();
}

/**
* Builder for KeyInfoWithVolumeContext.
*/
public static class Builder {
private OmVolumeArgs volumeArgs;
private String userPrincipal;
private OmKeyInfo keyInfo;

public Builder setVolumeArgs(OmVolumeArgs volumeArgs) {
this.volumeArgs = volumeArgs;
return this;
}

public Builder setUserPrincipal(String userPrincipal) {
this.userPrincipal = userPrincipal;
return this;
}

public Builder setKeyInfo(OmKeyInfo keyInfo) {
this.keyInfo = keyInfo;
return this;
}

public KeyInfoWithVolumeContext build() {
return new KeyInfoWithVolumeContext(volumeArgs, userPrincipal, keyInfo);
}
}
}
Loading