Skip to content

Commit

Permalink
Completed -swt with cli and web ui access.
Browse files Browse the repository at this point in the history
  • Loading branch information
dstreev committed Dec 6, 2024
1 parent cad4294 commit 6d9d8ba
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 18 deletions.
Binary file added Writerside/images/save-working-tables.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 24 additions & 1 deletion Writerside/topics/Index-of-Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,35 @@ This does NOT prevent data from being manipulated on the target cluster after th
<tab title="Config File">

```yaml
readOnly: true|false
readOnly: true|false
```

</tab>
</tabs>

## Save Working Tables

`saveWorkingTables` is a boolean value that determines if the working tables should be saved. The default value is `false`.

<tabs>
<tab title="CLI">

`-swt|--save-working-tables`

</tab>
<tab title="Web UI">

![save-working-tables.png](save-working-tables.png)

</tab>
<tab title="Config File">

```yaml
saveWorkingTables: true|false
```

</tab>
</tabs>

## Skip Features

Expand Down
8 changes: 7 additions & 1 deletion Writerside/topics/Release-Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ The latest set of known issues can be found [here](https://github.com/cloudera-l
The latest set of enhancement requests can be found [here](https://github.com/cloudera-labs/hms-mirror/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement).

If there is something you'd like to see, add a new issue [here](https://github.com/cloudera-labs/hms-mirror/issues)
## 2.2.0.19.4 (release)

## 2.2.0.19.6 (pre-release)

**What's New**
[BEHAVIOR CHANGE - Drop any shadow table definitions created during migration automatically](https://github.com/cloudera-labs/hms-mirror/issues/163)
> This adjustment will remove shadow tables that were created during the migration process. This will help to keep
> the source and target clusters clean of any artifacts created during the migration process. An option
> `saveWorkingTables` has been added to the configuration to allow you to keep these tables if you need them for any
> audits or other reasons. The default is `false`, which means that the tables will be dropped automatically. An audit
> 'cleanup' file with the drop commands will be created in the report directory, regardless of the setting.
## 2.2.0.19.2 (pre-release)

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<groupId>com.cloudera.utils.hadoop</groupId>
<artifactId>hms-mirror</artifactId>
<version>2.2.0.19.4</version>
<version>2.2.0.19.6</version>
<packaging>jar</packaging>

<name>hms-mirror</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,18 @@ CommandLineRunner configRightIsDisconnectedFalse(HmsMirrorConfig hmsMirrorConfig
};
}

@Bean
@Order(1)
@ConditionalOnProperty(
name = "hms-mirror.config.save-working-tables")
CommandLineRunner configSaveWorkingTables(HmsMirrorConfig hmsMirrorConfig, @Value("${hms-mirror.config.save-working-tables}") boolean value) {
return args -> {
log.warn("save-working-tables: {}", value);
hmsMirrorConfig.setSaveWorkingTables(value);
};
}


@Bean
@Order(1)
@ConditionalOnProperty(
Expand Down Expand Up @@ -1461,6 +1473,11 @@ private Options getOptions() {
resetToDefaultLocation.setRequired(Boolean.FALSE);
options.addOption(resetToDefaultLocation);

Option saveWorkingTables = new Option("swt", "save-working-tables", false,
"Save working tables (shadow tables) created during the migration process.");
saveWorkingTables.setRequired(Boolean.FALSE);
options.addOption(saveWorkingTables);

Option skipLegacyTranslation = new Option("slt", "skip-legacy-translation", false,
"Skip Schema Upgrades and Serde Translations");
skipLegacyTranslation.setRequired(Boolean.FALSE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public enum HmsMirrorCommandLineOptionsEnum {
READ_ONLY("ro", "read-only", null, ""),
RESET_RIGHT("rr", "reset-right", null, ""),
SYNC("s", "sync", null, ""),
SAVE_WORKING_TABLES("swt", "save-working-tables", null, ""),
SORT_DYNAMIC_PARTITION_INSERTS("sdpi", "sort-dynamic-partition-inserts", null, ""),
SKIP_FEATURES("sf", "skip-features", null, ""),
SKIP_LINK_CHECK("slc", "skip-link-check", null, ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,23 +628,12 @@ protected Boolean buildMigrationSql(TableMirror tableMirror, Environment origina
} else {
// Otherwise, we're on the RIGHT cluster and need to cleanup the 'shadow' table.
// Add USE clause to the SQL
String rightDatabase = HmsMirrorConfigUtil.getResolvedDB(tableMirror.getParent().getName(), config);
if (config.isSaveWorkingTables()) {
Pair cleanUp = new Pair("Post Migration Cleanup", "-- To be run AFTER final RIGHT SQL statements.");
targetEnvTable.addCleanUpSql(cleanUp);

String rightDatabase = HmsMirrorConfigUtil.getResolvedDB(tableMirror.getParent().getName(), config);

String useRightDb = MessageFormat.format(MirrorConf.USE, rightDatabase);
Pair leftRightPair = new Pair(TableUtils.USE_DESC, useRightDb);
targetEnvTable.addCleanUpSql(leftRightPair);

// Drop Shadow Table.
String dropTransferSql = MessageFormat.format(MirrorConf.DROP_TABLE, source.getName());
targetEnvTable.getCleanUpSql().add(new Pair(TableUtils.DROP_SHADOW_TABLE, dropTransferSql));
} else {
// Remove Shadow table as a part of the automatic cleanup.
String rightDatabase = HmsMirrorConfigUtil.getResolvedDB(tableMirror.getParent().getName(), config);

String useRightDb = MessageFormat.format(MirrorConf.USE, rightDatabase);
Pair leftRightPair = new Pair(TableUtils.USE_DESC, useRightDb);
targetEnvTable.addSql(leftRightPair);
Expand All @@ -653,6 +642,14 @@ protected Boolean buildMigrationSql(TableMirror tableMirror, Environment origina
String dropTransferSql = MessageFormat.format(MirrorConf.DROP_TABLE, source.getName());
targetEnvTable.getSql().add(new Pair(TableUtils.DROP_SHADOW_TABLE, dropTransferSql));
}
// Always generate the drop working table scripts.
String useRightDb = MessageFormat.format(MirrorConf.USE, rightDatabase);
Pair leftRightPair = new Pair(TableUtils.USE_DESC, useRightDb);
targetEnvTable.addCleanUpSql(leftRightPair);

// Drop Shadow Table.
String dropTransferSql = MessageFormat.format(MirrorConf.DROP_TABLE, source.getName());
targetEnvTable.getCleanUpSql().add(new Pair(TableUtils.DROP_SHADOW_TABLE, dropTransferSql));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ hms-mirror:
filename: "default.yaml"
setup: "false"
suppress-cli-warnings: "false"
save-working-tables: "false"
yaml:
# This controls the maximum number of bytes that can be read from a YAML file.
# The default value in SnakeYaml is 3MB. We've reset this to 100MB.
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ config.transfer.storageMigration.postfix=Storage Migration Postfix
config.sync=Sync
config.sqlOutput=SQL Output
config.skipLegacyTranslation=Skip Legacy Translation
config.saveWorkingTables=Save Working Tables
config.skipFeatures=Skip Features
config.resetToDefaultLocation=Reset to Default Location
config.resetRight=Reset Right
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/templates/fragments/config/misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
th:checked="${CONFIG.resetRight}"/>
<!-- <label for="resetRight" th:text="#{config.resetRight}"></label>-->
<!-- </div>-->
<div class="pure-control-group">
<label for="saveWorkingTables" th:text="#{config.saveWorkingTables}"></label>
<input type="checkbox" name="saveWorkingTables"
th:field="*{saveWorkingTables}"
th:checked="${CONFIG.saveWorkingTables}"/>
</div>
<div class="pure-control-group">
<label for="skipFeatures" th:text="#{config.skipFeatures}"></label>
<input type="checkbox" name="skipFeatures"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void returnCodeTest() {
@Test
public void validateTableIssueCount() {
validateTableIssueCount("ext_purge_odd_parts", "web_sales",
Environment.LEFT, 2);
Environment.LEFT, 3);

// assertEquals("Issue Count not as expected", 3,
// getConversion().getDatabase("ext_purge_odd_parts")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void returnCodeTest() {
// Get Runtime Return Code.
long rtn = getReturnCode();
// Verify the return code.
long check = 0L;
assertEquals("Return Code Failure: " + rtn, check * -1, rtn);
long check = 1L;
assertEquals("Return Code Failure: " + rtn, check, rtn);
}

// @Test
Expand Down

0 comments on commit 6d9d8ba

Please sign in to comment.