Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-10608. Recon can't get full key when using Recon API. #6492

Merged
merged 22 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f66979f
Adding a new parameter to NSSummary and exposing it
ArafatKhan2198 Apr 7, 2024
4dbab9a
HDDS-10608. Recon can't get full key when using Recon API.
ArafatKhan2198 Apr 7, 2024
f75aac2
Fixed bugs and checkstyle issues
ArafatKhan2198 Apr 7, 2024
a14592c
Merge branch 'master' into HDDS-10608
ArafatKhan2198 Apr 17, 2024
ee97fa6
Added Integration Tests to ContainerEndpoint
ArafatKhan2198 Apr 17, 2024
7faa2e1
Rebuilding tree to prevent backwards compatability
ArafatKhan2198 Apr 29, 2024
0d03da5
Finished the changes for preventing compatability issues
ArafatKhan2198 Apr 29, 2024
dd1016d
Revised the backporting strategy
ArafatKhan2198 Apr 29, 2024
0e7baa8
Made review changes
ArafatKhan2198 Apr 29, 2024
76f0e41
Made 2nd review changes
ArafatKhan2198 May 3, 2024
89f5d1e
Added command to terminate the thread
ArafatKhan2198 May 6, 2024
1c41bc6
Removed the unnecessary synchronised block
ArafatKhan2198 May 6, 2024
5773c18
Made final review comments
ArafatKhan2198 May 7, 2024
415d315
Added more logs and removed the boolean flag
ArafatKhan2198 May 7, 2024
f2e8511
Fixed checkstyle issues
ArafatKhan2198 May 7, 2024
5cb1cc5
Fixed failing integration teasrt
ArafatKhan2198 May 8, 2024
248a375
Added tests to check for backporting
ArafatKhan2198 May 8, 2024
047ac8b
Fixed checkstyle issues
ArafatKhan2198 May 8, 2024
fafc2e3
Fixed the missed checkstyle
ArafatKhan2198 May 8, 2024
50ac78f
Fixed the final review comments
ArafatKhan2198 May 8, 2024
d802e67
Changed the java doc as well
ArafatKhan2198 May 8, 2024
4c93221
Fixed find bugs
ArafatKhan2198 May 8, 2024
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,208 @@
package org.apache.hadoop.ozone.recon;

import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.client.BucketArgs;
import org.apache.hadoop.ozone.client.ObjectStore;
import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.client.OzoneVolume;
import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
import org.apache.hadoop.ozone.om.OMConfigKeys;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
import org.apache.hadoop.ozone.recon.api.ContainerEndpoint;
import org.apache.hadoop.ozone.recon.api.types.KeyMetadata;
import org.apache.hadoop.ozone.recon.api.types.KeysResponse;
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 org.apache.hadoop.ozone.recon.spi.impl.OzoneManagerServiceProviderImpl;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

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.*;

public class TestReconContainerEndpoint {

private static OzoneClient client;
private static MiniOzoneCluster cluster = null;
private static OzoneConfiguration conf;
private static ObjectStore store;

@BeforeAll
public static void init() throws Exception {
conf = new OzoneConfiguration();
conf.set(OMConfigKeys.OZONE_DEFAULT_BUCKET_LAYOUT,
OMConfigKeys.OZONE_BUCKET_LAYOUT_FILE_SYSTEM_OPTIMIZED);
cluster = MiniOzoneCluster.newBuilder(conf)
.setNumDatanodes(3)
.includeRecon(true)
.build();
cluster.waitForClusterToBeReady();
client = cluster.newClient();
store = client.getObjectStore();
}

@AfterAll
public static void shutdown() throws IOException {
if (client != null) {
client.close();
}
if (cluster != null) {
cluster.shutdown();
}
}

@Test
public void testContainerEndpointForFSOLayout() throws Exception {
// Setup: Create multiple volumes, buckets, and key hierarchies
String volName = "testvol";
String bucketName = "fsobucket";
// Scenario 1: Deeply nested directories
String nestedDirKey = "dir1/dir2/dir3/file1";
// Scenario 2: Single file in a bucket
String singleFileKey = "file1";

// Create volume and bucket
store.createVolume(volName);
OzoneVolume volume = store.getVolume(volName);
volume.createBucket(bucketName, BucketArgs.newBuilder()
.setBucketLayout(BucketLayout.FILE_SYSTEM_OPTIMIZED).build());

// Write keys to the bucket
writeTestData(volName, bucketName, nestedDirKey, "data1");
writeTestData(volName, bucketName, singleFileKey, "data2");

// Synchronize data from OM to Recon
OzoneManagerServiceProviderImpl impl = (OzoneManagerServiceProviderImpl)
cluster.getReconServer().getOzoneManagerServiceProvider();
impl.syncDataFromOM();

//Search for the bucket from the bucket table and verify its FSO
String buckKey = "/" + volName + "/" + bucketName;
OmBucketInfo bucketInfo =
cluster.getReconServer().getOzoneManagerServiceProvider()
.getOMMetadataManagerInstance().getBucketTable().get(buckKey);
assertNotNull(bucketInfo);
assertEquals(BucketLayout.FILE_SYSTEM_OPTIMIZED,
bucketInfo.getBucketLayout());

// Assuming a known container ID that these keys have been written into
long testContainerID = 1L;

// Query the ContainerEndpoint for the keys in the specified container
Response response = getContainerEndpointResponse(testContainerID);

assertNotNull(response, "Response should not be null.");
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus(),
"Expected HTTP 200 OK response.");

KeysResponse data = (KeysResponse) response.getEntity();
Collection<KeyMetadata> keyMetadataList = data.getKeys();

assertEquals(1, data.getTotalCount());
assertEquals(1, keyMetadataList.size());

// Assert the file name and the complete path.
KeyMetadata keyMetadata = keyMetadataList.iterator().next();
assertEquals("file1", keyMetadata.getKey());
assertEquals("testvol/testbucket/dir1/dir2/dir3/file1",
keyMetadata.getCompletePath());

testContainerID = 2L;
response = getContainerEndpointResponse(testContainerID);
data = (KeysResponse) response.getEntity();
keyMetadataList = data.getKeys();
assertEquals(1, data.getTotalCount());
assertEquals(1, keyMetadataList.size());

// Assert the file name and the complete path.
keyMetadata = keyMetadataList.iterator().next();
assertEquals("file1", keyMetadata.getKey());
assertEquals("testvol/testbucket/file1", keyMetadata.getCompletePath());
}

@Test
public void testContainerEndpointForOBSBucket() throws Exception {
String volumeName = "testvol";
String obsBucketName = "obsbucket";
String obsSingleFileKey = "file1";

// Setup volume and OBS bucket
store.createVolume(volumeName);
OzoneVolume volume = store.getVolume(volumeName);
volume.createBucket(obsBucketName,
BucketArgs.newBuilder().setBucketLayout(BucketLayout.OBJECT_STORE)
.build());

// Write a single file to the OBS bucket
writeTestData(volumeName, obsBucketName, obsSingleFileKey, "Hello OBS!");

OzoneManagerServiceProviderImpl impl =
(OzoneManagerServiceProviderImpl) cluster.getReconServer()
.getOzoneManagerServiceProvider();
impl.syncDataFromOM();

// Search for the bucket from the bucket table and verify its OBS
String bucketKey = "/" + volumeName + "/" + obsBucketName;
OmBucketInfo bucketInfo =
cluster.getReconServer().getOzoneManagerServiceProvider()
.getOMMetadataManagerInstance().getBucketTable().get(bucketKey);
assertNotNull(bucketInfo);
assertEquals(BucketLayout.OBJECT_STORE, bucketInfo.getBucketLayout());

// Initialize the ContainerEndpoint
long containerId = 1L;
Response response = getContainerEndpointResponse(containerId);

assertNotNull(response, "Response should not be null.");
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus(),
"Expected HTTP 200 OK response.");
KeysResponse data = (KeysResponse) response.getEntity();
Collection<KeyMetadata> keyMetadataList = data.getKeys();

assertEquals(1, data.getTotalCount());
assertEquals(1, keyMetadataList.size());

KeyMetadata keyMetadata = keyMetadataList.iterator().next();
assertEquals("file1", keyMetadata.getKey());
assertEquals("testvol/obsbucket/file1", keyMetadata.getCompletePath());
}

private Response getContainerEndpointResponse(long containerId) {
OzoneStorageContainerManager reconSCM =
cluster.getReconServer().getReconStorageContainerManager();
ReconContainerManager reconContainerManager =
(ReconContainerManager) reconSCM.getContainerManager();
ContainerHealthSchemaManager containerHealthSchemaManager =
reconContainerManager.getContainerSchemaManager();
ReconOMMetadataManager omMetadataManagerInstance =
(ReconOMMetadataManager)
cluster.getReconServer().getOzoneManagerServiceProvider()
.getOMMetadataManagerInstance();
ContainerEndpoint containerEndpoint =
new ContainerEndpoint(reconSCM, containerHealthSchemaManager,
cluster.getReconServer().getReconNamespaceSummaryManager(),
cluster.getReconServer().getReconContainerMetadataManager(),
omMetadataManagerInstance);
return containerEndpoint.getKeysForContainer(containerId, 10, "");
}

private void writeTestData(String volumeName, String bucketName,
String keyPath, String data) throws Exception {
try (OzoneOutputStream out = client.getObjectStore().getVolume(volumeName)
.getBucket(bucketName)
.createKey(keyPath, data.length())) {
out.write(data.getBytes());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Path;
Expand Down Expand Up @@ -55,13 +56,19 @@
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_EVENT_THREAD_POOL_SIZE_DEFAULT;
import static org.apache.hadoop.hdds.server.ServerUtils.getDirectoryFromConfig;
import static org.apache.hadoop.hdds.server.ServerUtils.getOzoneMetaDirPath;
import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
import static org.apache.hadoop.ozone.recon.ReconServerConfigKeys.OZONE_RECON_SCM_DB_DIR;
import static org.jooq.impl.DSL.currentTimestamp;
import static org.jooq.impl.DSL.select;
import static org.jooq.impl.DSL.using;

import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
import org.apache.hadoop.ozone.recon.api.types.NSSummary;
import org.apache.hadoop.ozone.recon.api.types.DUResponse;
import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
import org.apache.hadoop.ozone.recon.scm.ReconContainerReportQueue;
import org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager;
import org.apache.hadoop.security.authentication.client.AuthenticationException;
import org.hadoop.ozone.recon.schema.tables.daos.GlobalStatsDao;
import org.hadoop.ozone.recon.schema.tables.pojos.GlobalStats;
Expand Down Expand Up @@ -246,25 +253,74 @@ 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.
*
* @param omKeyInfo The OmKeyInfo object for the key
* @return The constructed full path of the key as a String.
* @throws IOException
*/
public static String constructFullPath(OmKeyInfo omKeyInfo,
ReconNamespaceSummaryManager reconNamespaceSummaryManager,
ReconOMMetadataManager omMetadataManager)
throws IOException {
StringBuilder fullPath = new StringBuilder(omKeyInfo.getKeyName());
long parentId = omKeyInfo.getParentObjectID();
boolean isDirectoryPresent = false;
while (parentId != -1) {
sumitagrawl marked this conversation as resolved.
Show resolved Hide resolved
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);
sumitagrawl marked this conversation as resolved.
Show resolved Hide resolved
return constructFullPath(omKeyInfo, reconNamespaceSummaryManager,
omMetadataManager);
}
fullPath.insert(0, nsSummary.getDirName() + OM_KEY_PREFIX);
sumitagrawl marked this conversation as resolved.
Show resolved Hide resolved

// Move to the parent ID of the current directory
parentId = nsSummary.getParentId();
isDirectoryPresent = true;
}

// Prepend the volume and bucket to the constructed path
String volumeName = omKeyInfo.getVolumeName();
sumitagrawl marked this conversation as resolved.
Show resolved Hide resolved
String bucketName = omKeyInfo.getBucketName();
fullPath.insert(0, volumeName + OM_KEY_PREFIX + bucketName + OM_KEY_PREFIX);
sumitagrawl marked this conversation as resolved.
Show resolved Hide resolved
if (isDirectoryPresent) {
return OmUtils.normalizeKey(fullPath.toString(), true);
}
return fullPath.toString();
}

/**
* Make HTTP GET call on the URL and return HttpURLConnection instance.
*
* @param connectionFactory URLConnectionFactory to use.
* @param url url to call
* @param isSpnego is SPNEGO enabled
* @param url url to call
* @param isSpnego is SPNEGO enabled
* @return HttpURLConnection instance of the HTTP call.
* @throws IOException, AuthenticationException While reading the response.
*/
public HttpURLConnection makeHttpCall(URLConnectionFactory connectionFactory,
String url, boolean isSpnego)
String url, boolean isSpnego)
throws IOException, AuthenticationException {
HttpURLConnection urlConnection = (HttpURLConnection)
connectionFactory.openConnection(new URL(url), isSpnego);
connectionFactory.openConnection(new URL(url), isSpnego);
urlConnection.connect();
return urlConnection;
}

/**
* Load last known DB in Recon.
*
* @param reconDbDir
* @param fileNamePrefix
* @return
Expand Down
Loading