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

feat(datahub-upgrade): Improve no code upgrade logging #2653

Merged
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
Expand Up @@ -32,40 +32,49 @@ public Function<UpgradeContext, UpgradeStepResult> executable() {

if (context.parsedArgs().containsKey(NoCodeUpgrade.FORCE_UPGRADE_ARG_NAME)) {
context.report().addLine("Forced upgrade detected. Proceeding with upgrade...");
return new DefaultUpgradeStepResult(
id(),
UpgradeStepResult.Result.SUCCEEDED);
return new DefaultUpgradeStepResult(id(), UpgradeStepResult.Result.SUCCEEDED);
}

try {
if (isQualified(_server)) {
if (isQualified(_server, context)) {
// Qualified.
context.report().addLine("Found qualified upgrade candidate. Proceeding with upgrade...");
return new DefaultUpgradeStepResult(
id(),
UpgradeStepResult.Result.SUCCEEDED);
return new DefaultUpgradeStepResult(id(), UpgradeStepResult.Result.SUCCEEDED);
}
// Unqualified (Table already exists)
context.report().addLine("Failed to qualify upgrade candidate. Aborting the upgrade...");
return new DefaultUpgradeStepResult(
id(),
UpgradeStepResult.Result.SUCCEEDED,
UpgradeStepResult.Action.ABORT);
return new DefaultUpgradeStepResult(id(), UpgradeStepResult.Result.SUCCEEDED, UpgradeStepResult.Action.ABORT);
} catch (Exception e) {
context.report().addLine(String.format("Failed to check if metadata_aspect_v2 table exists: %s", e.toString()));
return new DefaultUpgradeStepResult(
id(),
UpgradeStepResult.Result.FAILED);
return new DefaultUpgradeStepResult(id(), UpgradeStepResult.Result.FAILED);
}
};
}

private boolean isQualified(EbeanServer server) {

return AspectStorageValidationUtil.checkV1TableExists(server)
&& (
!AspectStorageValidationUtil.checkV2TableExists(server)
|| AspectStorageValidationUtil.getV2RowCount(server) == 0
);
// Check whether the upgrade is needed
private boolean isQualified(EbeanServer server, UpgradeContext context) {
boolean v1TableExists = AspectStorageValidationUtil.checkV1TableExists(server);
if (v1TableExists) {
context.report().addLine("-- V1 table exists");
long v1TableRowCount = AspectStorageValidationUtil.getV1RowCount(server);
context.report().addLine(String.format("-- V1 table has %d rows", v1TableRowCount));
boolean v2TableExists = AspectStorageValidationUtil.checkV2TableExists(server);
if (v2TableExists) {
context.report().addLine("-- V2 table exists");
long v2TableRowCount = AspectStorageValidationUtil.getV2RowCount(server);
if (v2TableRowCount == 0) {
context.report().addLine("-- V2 table is empty");
return true;
}
context.report().addLine(String.format("-- V2 table has %d rows", v2TableRowCount));
context.report().addLine("-- Since V2 table has records, we will not proceed with the upgrade. ");
context.report().addLine("-- If V2 table has significantly less rows, consider running the forced upgrade. ");
return false;
}
context.report().addLine("-- V2 table does not exist");
return true;
}
context.report().addLine("-- V1 table does not exist");
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.linkedin.metadata.entity;

import com.linkedin.metadata.entity.ebean.EbeanAspectV1;
import com.linkedin.metadata.entity.ebean.EbeanAspectV2;
import io.ebean.EbeanServer;
import io.ebean.SqlQuery;
Expand All @@ -11,6 +12,10 @@ private AspectStorageValidationUtil() {

}

public static long getV1RowCount(EbeanServer server) {
return server.find(EbeanAspectV1.class).findCount();
}

public static long getV2RowCount(EbeanServer server) {
return server.find(EbeanAspectV2.class).findCount();
}
Expand Down