-
Notifications
You must be signed in to change notification settings - Fork 45
Synchronizer: Add consolidated sync report and --fail-on-error flag #258
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
Merged
dimas-b
merged 3 commits into
apache:main
from
saidixith002:polaris-synchronizer/sync-report
Jul 27, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 134 additions & 35 deletions
169
...hronizer/api/src/main/java/org/apache/polaris/tools/sync/polaris/PolarisSynchronizer.java
Large diffs are not rendered by default.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
...zer/api/src/main/java/org/apache/polaris/tools/sync/polaris/planning/plan/EntityType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * 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.polaris.tools.sync.polaris.planning.plan; | ||
|
|
||
| /** The category of entity a {@link SynchronizationReport} outcome is recorded against. */ | ||
| public enum EntityType { | ||
| PRINCIPAL, | ||
| PRINCIPAL_ROLE, | ||
| PRINCIPAL_ROLE_ASSIGNMENT, | ||
| CATALOG, | ||
| CATALOG_ROLE, | ||
| CATALOG_ROLE_ASSIGNMENT, | ||
| GRANT, | ||
| NAMESPACE, | ||
| TABLE | ||
| } |
28 changes: 28 additions & 0 deletions
28
...er/api/src/main/java/org/apache/polaris/tools/sync/polaris/planning/plan/SyncOutcome.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * 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.polaris.tools.sync.polaris.planning.plan; | ||
|
|
||
| /** The outcome of an individual entity sync attempt, recorded in a {@link SynchronizationReport}. */ | ||
| public enum SyncOutcome { | ||
| CREATED, | ||
| OVERWRITTEN, | ||
| REMOVED, | ||
| SKIPPED, | ||
| FAILED | ||
| } |
140 changes: 140 additions & 0 deletions
140
.../main/java/org/apache/polaris/tools/sync/polaris/planning/plan/SynchronizationReport.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /* | ||
| * 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.polaris.tools.sync.polaris.planning.plan; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.EnumMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Accumulates the outcome of every individual entity sync attempt performed during a run, so that | ||
| * a single consolidated summary can be printed at the end instead of relying on interleaved logs. | ||
| */ | ||
| public class SynchronizationReport { | ||
|
|
||
| private record Failure(EntityType type, String identifier, String message) {} | ||
|
|
||
| private final Map<EntityType, Map<SyncOutcome, Integer>> counts; | ||
|
|
||
| private final List<Failure> failures; | ||
|
|
||
| public SynchronizationReport() { | ||
| this.counts = new EnumMap<>(EntityType.class); | ||
| for (EntityType type : EntityType.values()) { | ||
| Map<SyncOutcome, Integer> outcomeCounts = new EnumMap<>(SyncOutcome.class); | ||
| for (SyncOutcome outcome : SyncOutcome.values()) { | ||
| outcomeCounts.put(outcome, 0); | ||
| } | ||
| this.counts.put(type, outcomeCounts); | ||
| } | ||
| this.failures = new ArrayList<>(); | ||
| } | ||
|
|
||
| /** | ||
| * Records that an entity was successfully synced. | ||
| * | ||
| * @param type the category of entity that was synced | ||
| * @param outcome the outcome of the sync; must not be {@link SyncOutcome#FAILED} - use {@link | ||
| * #recordFailure(EntityType, String, Exception)} for failures | ||
| */ | ||
| public void recordSuccess(EntityType type, SyncOutcome outcome) { | ||
| if (outcome == SyncOutcome.FAILED) { | ||
| throw new IllegalArgumentException("Use recordFailure() to record a failed sync."); | ||
| } | ||
| Map<SyncOutcome, Integer> outcomeCounts = counts.get(type); | ||
| outcomeCounts.put(outcome, outcomeCounts.get(outcome) + 1); | ||
| } | ||
|
|
||
| /** | ||
| * Records that an entity failed to sync. | ||
| * | ||
| * @param type the category of entity that failed to sync | ||
| * @param identifier a human-readable identifier for the entity, e.g. its name | ||
| * @param cause the exception that caused the failure | ||
| */ | ||
| public void recordFailure(EntityType type, String identifier, Exception cause) { | ||
| Map<SyncOutcome, Integer> outcomeCounts = counts.get(type); | ||
| outcomeCounts.put(SyncOutcome.FAILED, outcomeCounts.get(SyncOutcome.FAILED) + 1); | ||
| failures.add(new Failure(type, identifier, cause.getMessage())); | ||
| } | ||
|
|
||
| /** Returns true if any entity failed to sync. */ | ||
| public boolean hasFailures() { | ||
| return !failures.isEmpty(); | ||
| } | ||
|
|
||
| private static String displayName(EntityType type) { | ||
| return switch (type) { | ||
| case PRINCIPAL -> "Principal"; | ||
| case PRINCIPAL_ROLE -> "PrincipalRole"; | ||
| case PRINCIPAL_ROLE_ASSIGNMENT -> "PrincipalRoleAssignment"; | ||
| case CATALOG -> "Catalog"; | ||
| case CATALOG_ROLE -> "CatalogRole"; | ||
| case CATALOG_ROLE_ASSIGNMENT -> "CatalogRoleAssignment"; | ||
| case GRANT -> "Grant"; | ||
| case NAMESPACE -> "Namespace"; | ||
| case TABLE -> "Table"; | ||
| }; | ||
| } | ||
|
|
||
| /** Renders the accumulated counts and failures as a human-readable text block. */ | ||
| public String render() { | ||
| StringBuilder sb = new StringBuilder(); | ||
| sb.append("=== Synchronization Report ===\n"); | ||
|
|
||
| for (EntityType type : EntityType.values()) { | ||
| Map<SyncOutcome, Integer> outcomeCounts = counts.get(type); | ||
| int total = | ||
| outcomeCounts.get(SyncOutcome.CREATED) | ||
| + outcomeCounts.get(SyncOutcome.OVERWRITTEN) | ||
| + outcomeCounts.get(SyncOutcome.REMOVED) | ||
| + outcomeCounts.get(SyncOutcome.SKIPPED) | ||
| + outcomeCounts.get(SyncOutcome.FAILED); | ||
|
|
||
| if (total == 0) { | ||
| continue; | ||
| } | ||
|
|
||
| sb.append( | ||
| String.format( | ||
| "%-24s%d created, %d overwritten, %d removed, %d skipped, %d failed%n", | ||
| displayName(type) + ":", | ||
| outcomeCounts.get(SyncOutcome.CREATED), | ||
| outcomeCounts.get(SyncOutcome.OVERWRITTEN), | ||
| outcomeCounts.get(SyncOutcome.REMOVED), | ||
| outcomeCounts.get(SyncOutcome.SKIPPED), | ||
| outcomeCounts.get(SyncOutcome.FAILED))); | ||
| } | ||
|
|
||
| if (hasFailures()) { | ||
| sb.append("\nFailures:\n"); | ||
| for (Failure failure : failures) { | ||
| sb.append( | ||
| String.format( | ||
| " - %s '%s': %s%n", | ||
| displayName(failure.type()), failure.identifier(), failure.message())); | ||
| } | ||
| } | ||
|
|
||
| sb.append("==============================="); | ||
|
|
||
| return sb.toString(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...t/java/org/apache/polaris/tools/sync/polaris/planning/plan/SynchronizationReportTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * 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.polaris.tools.sync.polaris.planning.plan; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class SynchronizationReportTest { | ||
|
|
||
| @Test | ||
| public void recordSuccessIncrementsOnlyTargetedCell() { | ||
| SynchronizationReport report = new SynchronizationReport(); | ||
|
|
||
| report.recordSuccess(EntityType.PRINCIPAL, SyncOutcome.CREATED); | ||
|
|
||
| String rendered = report.render(); | ||
|
|
||
| Assertions.assertTrue(rendered.contains("Principal:")); | ||
| Assertions.assertTrue(rendered.contains("1 created, 0 overwritten, 0 removed, 0 skipped, 0 failed")); | ||
| Assertions.assertFalse(rendered.contains("Catalog:")); | ||
| } | ||
|
|
||
| @Test | ||
| public void recordFailureIncrementsFailedCountAndCapturesIdentifierAndMessage() { | ||
| SynchronizationReport report = new SynchronizationReport(); | ||
|
|
||
| report.recordFailure(EntityType.TABLE, "db.orders", new RuntimeException("connection refused")); | ||
|
|
||
| String rendered = report.render(); | ||
|
|
||
| Assertions.assertTrue(rendered.contains("Table:")); | ||
| Assertions.assertTrue(rendered.contains("0 created, 0 overwritten, 0 removed, 0 skipped, 1 failed")); | ||
| Assertions.assertTrue(rendered.contains("Table 'db.orders': connection refused")); | ||
| } | ||
|
|
||
| @Test | ||
| public void hasFailuresIsFalseForAnAllSuccessReport() { | ||
| SynchronizationReport report = new SynchronizationReport(); | ||
|
|
||
| report.recordSuccess(EntityType.CATALOG, SyncOutcome.CREATED); | ||
| report.recordSuccess(EntityType.NAMESPACE, SyncOutcome.REMOVED); | ||
|
|
||
| Assertions.assertFalse(report.hasFailures()); | ||
| } | ||
|
|
||
| @Test | ||
| public void hasFailuresIsTrueOnceAnyFailureIsRecorded() { | ||
| SynchronizationReport report = new SynchronizationReport(); | ||
|
|
||
| report.recordSuccess(EntityType.CATALOG, SyncOutcome.CREATED); | ||
| report.recordFailure(EntityType.GRANT, "TABLE", new RuntimeException("boom")); | ||
|
|
||
| Assertions.assertTrue(report.hasFailures()); | ||
| } | ||
|
|
||
| @Test | ||
| public void renderOmitsAllZeroEntityTypesAndFailuresSectionWhenEmpty() { | ||
| SynchronizationReport report = new SynchronizationReport(); | ||
|
|
||
| report.recordSuccess(EntityType.PRINCIPAL_ROLE, SyncOutcome.CREATED); | ||
|
|
||
| String rendered = report.render(); | ||
|
|
||
| Assertions.assertTrue(rendered.contains("PrincipalRole:")); | ||
| Assertions.assertFalse(rendered.contains("Grant:")); | ||
| Assertions.assertFalse(rendered.contains("Namespace:")); | ||
| Assertions.assertFalse(rendered.contains("Failures:")); | ||
| } | ||
|
|
||
| @Test | ||
| public void renderIncludesEachFailureWhenMultipleFailuresExist() { | ||
| SynchronizationReport report = new SynchronizationReport(); | ||
|
|
||
| report.recordFailure(EntityType.PRINCIPAL, "alice", new RuntimeException("timeout")); | ||
| report.recordFailure(EntityType.TABLE, "db.returns", new RuntimeException("not found")); | ||
|
|
||
| String rendered = report.render(); | ||
|
|
||
| Assertions.assertTrue(rendered.contains("Failures:")); | ||
| Assertions.assertTrue(rendered.contains("Principal 'alice': timeout")); | ||
| Assertions.assertTrue(rendered.contains("Table 'db.returns': not found")); | ||
| } | ||
|
|
||
| @Test | ||
| public void recordSuccessWithSkippedIncrementsSkippedCountAndDoesNotCountAsFailure() { | ||
| SynchronizationReport report = new SynchronizationReport(); | ||
|
|
||
| report.recordSuccess(EntityType.NAMESPACE, SyncOutcome.SKIPPED); | ||
|
|
||
| String rendered = report.render(); | ||
|
|
||
| Assertions.assertTrue(rendered.contains("Namespace:")); | ||
| Assertions.assertTrue(rendered.contains("0 created, 0 overwritten, 0 removed, 1 skipped, 0 failed")); | ||
| Assertions.assertFalse(report.hasFailures()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Map.compute()?