Skip to content

Commit

Permalink
Made review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArafatKhan2198 committed Apr 29, 2024
1 parent dd1016d commit 0e7baa8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* 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.recon;

import org.apache.hadoop.hdds.conf.OzoneConfiguration;
Expand All @@ -17,7 +35,7 @@
import org.apache.hadoop.ozone.recon.persistence.ContainerHealthSchemaManager;
import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
import org.apache.hadoop.ozone.recon.scm.ReconContainerManager;
import org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager;
import java.nio.charset.StandardCharsets;
import org.apache.hadoop.ozone.recon.spi.impl.OzoneManagerServiceProviderImpl;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -26,7 +44,6 @@
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -201,7 +218,7 @@ private void writeTestData(String volumeName, String bucketName,
try (OzoneOutputStream out = client.getObjectStore().getVolume(volumeName)
.getBucket(bucketName)
.createKey(keyPath, data.length())) {
out.write(data.getBytes());
out.write(data.getBytes(StandardCharsets.UTF_8));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -256,7 +257,7 @@ public void untarCheckpointFile(File tarFile, Path destPath)

/**
* Constructs the full path of a key from its OmKeyInfo using a bottom-up approach, starting from the leaf node.
* <p>
*
* The method begins with the leaf node (the key itself) and recursively prepends parent directory names, fetched
* via NSSummary objects, until reaching the parent bucket (parentId is -1). It effectively builds the path from
* bottom to top, finally prepending the volume and bucket names to complete the full path.
Expand All @@ -272,16 +273,17 @@ public static String constructFullPath(OmKeyInfo omKeyInfo,
StringBuilder fullPath = new StringBuilder(omKeyInfo.getKeyName());
long parentId = omKeyInfo.getParentObjectID();
boolean isDirectoryPresent = false;
while (parentId != -1) {
boolean rebuildTriggered = false;

while (parentId != 0) {
NSSummary nsSummary = reconNamespaceSummaryManager.getNSSummary(parentId);
if (nsSummary == null) {
break;
}
if (nsSummary.getParentId() == -1) {
// Call reprocess method if parentId is negative, as it has not been set for this yet.
reconNamespaceSummaryManager.rebuildNSSummaryTree(omMetadataManager);
return constructFullPath(omKeyInfo, reconNamespaceSummaryManager,
omMetadataManager);
if (nsSummary.getParentId() == -1 && !rebuildTriggered) {
// Trigger rebuild asynchronously and continue path construction
triggerRebuild(reconNamespaceSummaryManager, omMetadataManager);
rebuildTriggered = true; // Prevent multiple rebuild triggers
}
fullPath.insert(0, nsSummary.getDirName() + OM_KEY_PREFIX);

Expand All @@ -300,6 +302,14 @@ public static String constructFullPath(OmKeyInfo omKeyInfo,
return fullPath.toString();
}

private static void triggerRebuild(ReconNamespaceSummaryManager reconNamespaceSummaryManager,
ReconOMMetadataManager omMetadataManager) {
// Run this method in a separate thread
Executors.newSingleThreadExecutor().submit(() -> {
reconNamespaceSummaryManager.rebuildNSSummaryTree(omMetadataManager);
});
}

/**
* Make HTTP GET call on the URL and return HttpURLConnection instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ public NSSummary fromPersistedFormat(byte[] rawData) throws IOException {
assert (bytesRead == strLen);
String dirName = stringCodec.fromPersistedFormat(buffer);
res.setDirName(dirName);
long parentId = in.readLong();
if (parentId == 0) {
// Set the parent ID to -1 to indicate that it is old data from
// the cluster and the value has not yet been set.

// Check if there is enough data available to read the parentId
if (in.available() >= Long.BYTES) {
long parentId = in.readLong();
res.setParentId(parentId);
} else {
// Set default parentId to -1 indicating it's from old format
res.setParentId(-1);
return res;
}
res.setParentId(parentId);
return res;
}

Expand Down

0 comments on commit 0e7baa8

Please sign in to comment.