Skip to content

Commit

Permalink
Rebuilding tree to prevent backwards compatability
Browse files Browse the repository at this point in the history
  • Loading branch information
ArafatKhan2198 committed Apr 29, 2024
1 parent ee97fa6 commit 7faa2e1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
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 @@ -292,6 +293,19 @@ public static String constructFullPath(OmKeyInfo omKeyInfo,
return fullPath.toString();
}

public static boolean hasParentIdField(NSSummary nsSummary) {
Field field;
try {
// This line attempts to get the Field object representing the parentId
// field from the NSSummary class. If the parentId field does not exist,
// a NoSuchFieldException will be thrown.
field = NSSummary.class.getDeclaredField("parentId");
return true;
} catch (NoSuchFieldException e) {
return false; // Field not present
}
}


/**
* 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 @@ -21,6 +21,7 @@
import org.apache.hadoop.hdds.annotation.InterfaceStability;
import org.apache.hadoop.hdds.utils.db.BatchOperation;
import org.apache.hadoop.hdds.utils.db.RDBBatchOperation;
import org.apache.hadoop.ozone.om.OMMetadataManager;
import org.apache.hadoop.ozone.recon.api.types.NSSummary;

import java.io.IOException;
Expand All @@ -45,4 +46,6 @@ void batchStoreNSSummaries(BatchOperation batch, long objectId,

void commitBatchOperation(RDBBatchOperation rdbBatchOperation)
throws IOException;

void rebuildNSSummaryTree(OMMetadataManager omMetadataManager);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
import org.apache.hadoop.hdds.utils.db.DBStore;
import org.apache.hadoop.hdds.utils.db.RDBBatchOperation;
import org.apache.hadoop.hdds.utils.db.Table;
import org.apache.hadoop.ozone.om.OMMetadataManager;
import org.apache.hadoop.ozone.recon.api.types.NSSummary;
import org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager;
import org.apache.hadoop.ozone.recon.tasks.NSSummaryTask;

import static org.apache.hadoop.ozone.recon.spi.impl.ReconDBProvider.truncateTable;

import javax.inject.Inject;
Expand All @@ -39,12 +42,14 @@ public class ReconNamespaceSummaryManagerImpl

private Table<Long, NSSummary> nsSummaryTable;
private DBStore namespaceDbStore;
private NSSummaryTask nsSummaryTask;

@Inject
public ReconNamespaceSummaryManagerImpl(ReconDBProvider reconDBProvider)
public ReconNamespaceSummaryManagerImpl(ReconDBProvider reconDBProvider, NSSummaryTask nsSummaryTask)
throws IOException {
namespaceDbStore = reconDBProvider.getDbStore();
this.nsSummaryTable = NAMESPACE_SUMMARY.getTable(namespaceDbStore);
this.nsSummaryTask = nsSummaryTask;
}

@Override
Expand Down Expand Up @@ -81,6 +86,11 @@ public void commitBatchOperation(RDBBatchOperation rdbBatchOperation)
this.namespaceDbStore.commitBatchOperation(rdbBatchOperation);
}

@Override
public void rebuildNSSummaryTree(OMMetadataManager omMetadataManager) {
nsSummaryTask.reprocess(omMetadataManager);
}

public Table getNSSummaryTable() {
return nsSummaryTable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Map;

import static org.apache.hadoop.ozone.recon.ReconServerConfigKeys.OZONE_RECON_NSSUMMARY_FLUSH_TO_DB_MAX_THRESHOLD;
import static org.apache.hadoop.ozone.recon.ReconServerConfigKeys.OZONE_RECON_NSSUMMARY_FLUSH_TO_DB_MAX_THRESHOLD_DEFAULT;
import static org.apache.hadoop.ozone.recon.ReconUtils.hasParentIdField;

/**
* Class for holding all NSSummaryTask methods
Expand Down Expand Up @@ -125,11 +127,15 @@ protected void handlePutDirEvent(OmDirectoryInfo directoryInfo,
if (curNSSummary == null) {
// If we don't have it in this batch we try to get it from the DB
curNSSummary = reconNamespaceSummaryManager.getNSSummary(objectId);
}
if (curNSSummary == null) {
// If we don't have it locally and in the DB we create a new instance
// as this is a new ID
curNSSummary = new NSSummary();
if (curNSSummary == null) {
// If we don't have it locally and in the DB we create a new instance
// as this is a new ID
curNSSummary = new NSSummary();
} else if (!hasParentIdField(curNSSummary)) {
// Call reprocess method if parentId is missing
reconNamespaceSummaryManager.rebuildNSSummaryTree(reconOMMetadataManager);
curNSSummary = reconNamespaceSummaryManager.getNSSummary(objectId);
}
}
curNSSummary.setDirName(dirName);
// Set the parent directory ID
Expand All @@ -145,6 +151,11 @@ protected void handlePutDirEvent(OmDirectoryInfo directoryInfo,
// If we don't have it in this batch we try to get it from the DB
nsSummary = reconNamespaceSummaryManager.getNSSummary(parentObjectId);
}
if (nsSummary != null && !hasParentIdField(nsSummary)) {
// Call reprocess method if parentId is missing
reconNamespaceSummaryManager.rebuildNSSummaryTree(reconOMMetadataManager);
nsSummary = reconNamespaceSummaryManager.getNSSummary(objectId);
}
if (nsSummary == null) {
// If we don't have it locally and in the DB we create a new instance
// as this is a new ID
Expand Down

0 comments on commit 7faa2e1

Please sign in to comment.