siddhantsangwan commented on code in PR #9439: URL: https://github.com/apache/ozone/pull/9439#discussion_r2663818816
########## hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/SCMDatanodeCapacityInfo.java: ########## @@ -0,0 +1,181 @@ +/* + * 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.hdds.scm; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.MetadataStorageReportProto; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.StorageReportProto; + +/** + * Assessment result for whether a datanode has sufficient space for container placement. + * + * Tracks data and metadata volume requirements separately and provides debugging + * information about volumes with insufficient space. + */ +public class SCMDatanodeCapacityInfo { + + private final DatanodeDetails datanodeDetails; + private final VolumeInfo dataVolumeInfo; + private final VolumeInfo metaVolumeInfo; + + SCMDatanodeCapacityInfo( + DatanodeDetails datanodeDetails, long requiredDataSize, long requiredMetadataSize) { + this.datanodeDetails = datanodeDetails; + this.dataVolumeInfo = new VolumeInfo(requiredDataSize); + this.metaVolumeInfo = new VolumeInfo(requiredMetadataSize); + } + + /** @return true if datanode has sufficient space for both data and metadata */ + public boolean hasEnoughSpace() { + return dataVolumeInfo.hasEnoughSpace() && metaVolumeInfo.hasEnoughSpace(); + } + + public boolean hasEnoughDataSpace() { + return dataVolumeInfo.hasEnoughSpace(); + } + + public void markEnoughSpaceFoundForData() { + this.dataVolumeInfo.markEnoughSpaceFound(); + } + + public void updateMostAvailableSpaceForData(long mostSpaceAvailable) { + this.dataVolumeInfo.updateMostAvailableSpace(mostSpaceAvailable); + } + + public void addFullDataVolume(StorageReportProto report, long usableSpace) { + this.dataVolumeInfo.addFullVolume(new FullVolume(report.getStorageUuid(), usableSpace)); + } + + public boolean hasEnoughMetaSpace() { + return metaVolumeInfo.hasEnoughSpace(); + } + + public void markEnoughSpaceFoundForMeta() { + this.metaVolumeInfo.markEnoughSpaceFound(); + } + + public void updateMostAvailableSpaceForMeta(long mostSpaceAvailable) { + this.metaVolumeInfo.updateMostAvailableSpace(mostSpaceAvailable); + } + + public void addFullMetaVolume(MetadataStorageReportProto report) { + this.metaVolumeInfo.addFullVolume(new FullVolume(report.getStorageLocation(), report.getRemaining())); + } + + /** + * Gets a formatted message for logging capacity check failures. + * @return human-readable message explaining why this datanode was rejected + */ + public String getInsufficientSpaceMessage() { + if (hasEnoughSpace()) { + return String.format("Datanode %s has sufficient space (data: %d bytes required, metadata: %d bytes required)", + datanodeDetails.getUuidString(), dataVolumeInfo.requiredSpace, metaVolumeInfo.requiredSpace); + } + + if (!hasEnoughDataSpace()) { + return String.format("Datanode %s has no volumes with enough space to allocate %d bytes for data." + + " data=%s, metadata=%s", datanodeDetails.getUuidString(), dataVolumeInfo.requiredSpace, dataVolumeInfo, + metaVolumeInfo); + } else { + return String.format("Datanode %s has no volumes with enough space to allocate %d bytes for metadata." + + " data=%s, metadata=%s", datanodeDetails.getUuidString(), metaVolumeInfo.requiredSpace, dataVolumeInfo, + metaVolumeInfo); + } + } + + @Override + public String toString() { + return "SCMDatanodeCapacityInfo{" + + "datanode=" + datanodeDetails.getUuidString() + Review Comment: Same, use ip address or hostname. ########## hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/SCMDatanodeCapacityInfo.java: ########## @@ -0,0 +1,181 @@ +/* + * 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.hdds.scm; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.MetadataStorageReportProto; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.StorageReportProto; + +/** + * Assessment result for whether a datanode has sufficient space for container placement. + * + * Tracks data and metadata volume requirements separately and provides debugging + * information about volumes with insufficient space. + */ +public class SCMDatanodeCapacityInfo { + + private final DatanodeDetails datanodeDetails; + private final VolumeInfo dataVolumeInfo; + private final VolumeInfo metaVolumeInfo; + + SCMDatanodeCapacityInfo( + DatanodeDetails datanodeDetails, long requiredDataSize, long requiredMetadataSize) { + this.datanodeDetails = datanodeDetails; + this.dataVolumeInfo = new VolumeInfo(requiredDataSize); + this.metaVolumeInfo = new VolumeInfo(requiredMetadataSize); + } + + /** @return true if datanode has sufficient space for both data and metadata */ + public boolean hasEnoughSpace() { + return dataVolumeInfo.hasEnoughSpace() && metaVolumeInfo.hasEnoughSpace(); + } + + public boolean hasEnoughDataSpace() { + return dataVolumeInfo.hasEnoughSpace(); + } + + public void markEnoughSpaceFoundForData() { + this.dataVolumeInfo.markEnoughSpaceFound(); + } + + public void updateMostAvailableSpaceForData(long mostSpaceAvailable) { + this.dataVolumeInfo.updateMostAvailableSpace(mostSpaceAvailable); + } + + public void addFullDataVolume(StorageReportProto report, long usableSpace) { + this.dataVolumeInfo.addFullVolume(new FullVolume(report.getStorageUuid(), usableSpace)); + } + + public boolean hasEnoughMetaSpace() { + return metaVolumeInfo.hasEnoughSpace(); + } + + public void markEnoughSpaceFoundForMeta() { + this.metaVolumeInfo.markEnoughSpaceFound(); + } + + public void updateMostAvailableSpaceForMeta(long mostSpaceAvailable) { + this.metaVolumeInfo.updateMostAvailableSpace(mostSpaceAvailable); + } + + public void addFullMetaVolume(MetadataStorageReportProto report) { + this.metaVolumeInfo.addFullVolume(new FullVolume(report.getStorageLocation(), report.getRemaining())); + } + + /** + * Gets a formatted message for logging capacity check failures. + * @return human-readable message explaining why this datanode was rejected + */ + public String getInsufficientSpaceMessage() { + if (hasEnoughSpace()) { + return String.format("Datanode %s has sufficient space (data: %d bytes required, metadata: %d bytes required)", + datanodeDetails.getUuidString(), dataVolumeInfo.requiredSpace, metaVolumeInfo.requiredSpace); + } + + if (!hasEnoughDataSpace()) { + return String.format("Datanode %s has no volumes with enough space to allocate %d bytes for data." + + " data=%s, metadata=%s", datanodeDetails.getUuidString(), dataVolumeInfo.requiredSpace, dataVolumeInfo, + metaVolumeInfo); + } else { + return String.format("Datanode %s has no volumes with enough space to allocate %d bytes for metadata." + + " data=%s, metadata=%s", datanodeDetails.getUuidString(), metaVolumeInfo.requiredSpace, dataVolumeInfo, + metaVolumeInfo); + } Review Comment: Like I said above, perhaps it's better to only include datanode level total space, used, available, reserved, committed etc. and exclude volumes. ########## hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/SCMDatanodeCapacityInfo.java: ########## @@ -0,0 +1,181 @@ +/* + * 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.hdds.scm; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.MetadataStorageReportProto; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.StorageReportProto; + +/** + * Assessment result for whether a datanode has sufficient space for container placement. + * + * Tracks data and metadata volume requirements separately and provides debugging + * information about volumes with insufficient space. + */ +public class SCMDatanodeCapacityInfo { + + private final DatanodeDetails datanodeDetails; + private final VolumeInfo dataVolumeInfo; + private final VolumeInfo metaVolumeInfo; + + SCMDatanodeCapacityInfo( + DatanodeDetails datanodeDetails, long requiredDataSize, long requiredMetadataSize) { + this.datanodeDetails = datanodeDetails; + this.dataVolumeInfo = new VolumeInfo(requiredDataSize); + this.metaVolumeInfo = new VolumeInfo(requiredMetadataSize); + } + + /** @return true if datanode has sufficient space for both data and metadata */ + public boolean hasEnoughSpace() { + return dataVolumeInfo.hasEnoughSpace() && metaVolumeInfo.hasEnoughSpace(); + } + + public boolean hasEnoughDataSpace() { + return dataVolumeInfo.hasEnoughSpace(); + } + + public void markEnoughSpaceFoundForData() { + this.dataVolumeInfo.markEnoughSpaceFound(); + } + + public void updateMostAvailableSpaceForData(long mostSpaceAvailable) { + this.dataVolumeInfo.updateMostAvailableSpace(mostSpaceAvailable); + } + + public void addFullDataVolume(StorageReportProto report, long usableSpace) { + this.dataVolumeInfo.addFullVolume(new FullVolume(report.getStorageUuid(), usableSpace)); + } + + public boolean hasEnoughMetaSpace() { + return metaVolumeInfo.hasEnoughSpace(); + } + + public void markEnoughSpaceFoundForMeta() { + this.metaVolumeInfo.markEnoughSpaceFound(); + } + + public void updateMostAvailableSpaceForMeta(long mostSpaceAvailable) { + this.metaVolumeInfo.updateMostAvailableSpace(mostSpaceAvailable); + } + + public void addFullMetaVolume(MetadataStorageReportProto report) { + this.metaVolumeInfo.addFullVolume(new FullVolume(report.getStorageLocation(), report.getRemaining())); + } + + /** + * Gets a formatted message for logging capacity check failures. + * @return human-readable message explaining why this datanode was rejected + */ + public String getInsufficientSpaceMessage() { + if (hasEnoughSpace()) { + return String.format("Datanode %s has sufficient space (data: %d bytes required, metadata: %d bytes required)", + datanodeDetails.getUuidString(), dataVolumeInfo.requiredSpace, metaVolumeInfo.requiredSpace); Review Comment: Use Datanode ip address or hostname instead of UUID. Makes debugging easier. ########## hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/SCMDatanodeCapacityInfo.java: ########## @@ -0,0 +1,181 @@ +/* + * 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.hdds.scm; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.MetadataStorageReportProto; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.StorageReportProto; + +/** + * Assessment result for whether a datanode has sufficient space for container placement. + * + * Tracks data and metadata volume requirements separately and provides debugging + * information about volumes with insufficient space. + */ +public class SCMDatanodeCapacityInfo { + + private final DatanodeDetails datanodeDetails; + private final VolumeInfo dataVolumeInfo; + private final VolumeInfo metaVolumeInfo; + + SCMDatanodeCapacityInfo( + DatanodeDetails datanodeDetails, long requiredDataSize, long requiredMetadataSize) { + this.datanodeDetails = datanodeDetails; + this.dataVolumeInfo = new VolumeInfo(requiredDataSize); + this.metaVolumeInfo = new VolumeInfo(requiredMetadataSize); + } + + /** @return true if datanode has sufficient space for both data and metadata */ + public boolean hasEnoughSpace() { + return dataVolumeInfo.hasEnoughSpace() && metaVolumeInfo.hasEnoughSpace(); + } + + public boolean hasEnoughDataSpace() { + return dataVolumeInfo.hasEnoughSpace(); + } + + public void markEnoughSpaceFoundForData() { + this.dataVolumeInfo.markEnoughSpaceFound(); + } + + public void updateMostAvailableSpaceForData(long mostSpaceAvailable) { + this.dataVolumeInfo.updateMostAvailableSpace(mostSpaceAvailable); + } + + public void addFullDataVolume(StorageReportProto report, long usableSpace) { + this.dataVolumeInfo.addFullVolume(new FullVolume(report.getStorageUuid(), usableSpace)); Review Comment: Better to use volume path instead of storage uuid. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
