Skip to content

Commit ba07768

Browse files
authored
Merge pull request #7 from SAP/develop
Fix minor issues
2 parents aec6b33 + e921a88 commit ba07768

File tree

17 files changed

+93
-36
lines changed

17 files changed

+93
-36
lines changed

commercedbsync/src/com/sap/cx/boosters/commercedbsync/concurrent/impl/DefaultDataPipeFactory.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private void scheduleWorkers(CopyContext context, DataWorkerExecutor<Boolean> wo
107107
context.getMigrationContext().getDataSourceRepository());
108108
String table = copyItem.getSourceItem();
109109
long totalRows = copyItem.getRowCount();
110-
long pageSize = context.getMigrationContext().getReaderBatchSize();
110+
long pageSize = getReaderBatchSizeForTable(context, table);
111111
try {
112112
PerformanceRecorder recorder = context.getPerformanceProfiler().createRecorder(PerformanceCategory.DB_READ,
113113
table);
@@ -237,4 +237,9 @@ private void scheduleWorkers(CopyContext context, DataWorkerExecutor<Boolean> wo
237237
throw new RuntimeException("Exception while preparing reader tasks", ex);
238238
}
239239
}
240+
241+
private static int getReaderBatchSizeForTable(final CopyContext context, final String tableName) {
242+
Integer tableBatchSize = context.getMigrationContext().getReaderBatchSize(tableName);
243+
return tableBatchSize == null ? context.getMigrationContext().getReaderBatchSize() : tableBatchSize;
244+
}
240245
}

commercedbsync/src/com/sap/cx/boosters/commercedbsync/constants/CommercedbsyncConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public final class CommercedbsyncConstants extends GeneratedCommercedbsyncConsta
2424
public static final String MIGRATION_SCHEMA_AUTOTRIGGER_ENABLED = "migration.schema.autotrigger.enabled";
2525
public static final String MIGRATION_DATA_FULLDATABASE = "migration.data.fulldatabase.enabled";
2626
public static final String MIGRATION_DATA_READER_BATCHSIZE = "migration.data.reader.batchsize";
27+
public static final String MIGRATION_DATA_READER_BATCHSIZE_FOR_TABLE = "migration.data.reader.batchsize.{table}";
2728
public static final String MIGRATION_DATA_TRUNCATE_ENABLED = "migration.data.truncate.enabled";
2829
public static final String MIGRATION_DATA_TRUNCATE_EXCLUDED = "migration.data.truncate.excluded";
2930
public static final String MIGRATION_DATA_WORKERS_READER_MAXTASKS = "migration.data.workers.reader.maxtasks";

commercedbsync/src/com/sap/cx/boosters/commercedbsync/context/MigrationContext.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public interface MigrationContext {
3838

3939
int getReaderBatchSize();
4040

41+
/**
42+
* Retrieves the batch size for an individual table if available.
43+
*
44+
* @param tableName
45+
* @return int if configured or null if not defined for the given tableName
46+
*/
47+
Integer getReaderBatchSize(final String tableName);
48+
4149
boolean isTruncateEnabled();
4250

4351
boolean isAuditTableMigrationEnabled();

commercedbsync/src/com/sap/cx/boosters/commercedbsync/context/impl/DefaultIncrementalMigrationContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public void setLpTableMigrationEnabled(boolean lpTableMigrationEnabled) {
120120
@Override
121121
public void refreshSelf() {
122122
LOG.info("Refreshing Context");
123+
super.refreshSelf();
123124
// lists
124125
this.setIncludedTables(Collections.emptySet());
125126
this.setIncrementalTables(Collections.emptySet());

commercedbsync/src/com/sap/cx/boosters/commercedbsync/context/impl/DefaultMigrationContext.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class DefaultMigrationContext implements MigrationContext {
4141

4242
protected final Configuration configuration;
4343

44+
protected Set<String> tableViewNames;
45+
4446
public DefaultMigrationContext(final DataRepositoryFactory dataRepositoryFactory,
4547
final DataSourceConfigurationFactory dataSourceConfigurationFactory, final Configuration configuration)
4648
throws Exception {
@@ -110,6 +112,13 @@ public int getReaderBatchSize() {
110112
return getNumericProperty(CommercedbsyncConstants.MIGRATION_DATA_READER_BATCHSIZE);
111113
}
112114

115+
@Override
116+
public Integer getReaderBatchSize(final String tableName) {
117+
String tblConfKey = CommercedbsyncConstants.MIGRATION_DATA_READER_BATCHSIZE_FOR_TABLE.replace("{table}",
118+
tableName);
119+
return configuration.getInteger(tblConfKey, null);
120+
}
121+
113122
@Override
114123
public boolean isTruncateEnabled() {
115124
return getBooleanProperty(CommercedbsyncConstants.MIGRATION_DATA_TRUNCATE_ENABLED);
@@ -295,7 +304,9 @@ public void setFullDatabaseMigrationEnabled(final boolean enabled) {
295304

296305
@Override
297306
public void refreshSelf() {
298-
307+
// resetting "cached" view names as they may have changed when reusing a context
308+
// in job iterations.
309+
this.tableViewNames = null;
299310
}
300311

301312
@Override
@@ -357,9 +368,11 @@ public String getItemTypeViewNamePattern() {
357368

358369
@Override
359370
public String getItemTypeViewNameByTable(String tableName, DataRepository repository) throws SQLException {
360-
Set<String> views = repository.getAllViewNames();
371+
if (tableViewNames == null) {
372+
tableViewNames = repository.getAllViewNames();
373+
}
361374
String possibleVieName = String.format(StringUtils.trimToEmpty(getItemTypeViewNamePattern()), tableName);
362-
return views.contains(possibleVieName) ? possibleVieName : tableName;
375+
return tableViewNames.contains(possibleVieName) ? possibleVieName : tableName;
363376
}
364377

365378
@Override

commercedbsync/src/com/sap/cx/boosters/commercedbsync/dataset/impl/DefaultDataSet.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ public Object getColumnValue(String columnName, List<Object> row, DataColumn sou
7070
}
7171
break;
7272
case SMALLINT :
73-
if (targetColumnType == CHAR && StringUtils.isNumeric(String.valueOf(columnValue))) {
74-
columnValue = Character.toString((char) ((Integer) columnValue).intValue());
73+
if (targetColumnType == CHAR && StringUtils.isNumeric(String.valueOf(columnValue))
74+
&& columnValue instanceof Number) {
75+
columnValue = Character.toString((char) ((Number) columnValue).intValue());
7576
}
7677
break;
7778
default :

commercedbsync/src/com/sap/cx/boosters/commercedbsync/service/impl/DefaultDatabaseCopyTaskRepository.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public String getMostRecentMigrationID(MigrationContext context) {
7878
}
7979

8080
@Override
81-
public void createMigrationStatus(CopyContext context) throws Exception {
81+
public synchronized void createMigrationStatus(CopyContext context) throws Exception {
8282
String insert = "INSERT INTO " + TABLECOPYSTATUS + " (migrationId, total) VALUES (?, ?)";
8383
try (Connection conn = getConnection(context); PreparedStatement stmt = conn.prepareStatement(insert)) {
8484
stmt.setObject(1, context.getMigrationId());
@@ -88,7 +88,7 @@ public void createMigrationStatus(CopyContext context) throws Exception {
8888
}
8989

9090
@Override
91-
public void resetMigration(CopyContext context) throws Exception {
91+
public synchronized void resetMigration(CopyContext context) throws Exception {
9292
String update = "UPDATE " + TABLECOPYSTATUS
9393
+ " SET completed = total - failed, status = ?, failed=?, lastUpdate=? WHERE migrationId = ?";
9494
try (Connection conn = getConnection(context); PreparedStatement stmt = conn.prepareStatement(update)) {
@@ -106,7 +106,7 @@ public void setMigrationStatus(CopyContext context, MigrationProgress progress)
106106
}
107107

108108
@Override
109-
public boolean setMigrationStatus(CopyContext context, MigrationProgress from, MigrationProgress to)
109+
public synchronized boolean setMigrationStatus(CopyContext context, MigrationProgress from, MigrationProgress to)
110110
throws Exception {
111111
final String update = "UPDATE " + TABLECOPYSTATUS + " SET status = ? WHERE status = ? AND migrationId = ?";
112112
try (Connection conn = getConnection(context); PreparedStatement stmt = conn.prepareStatement(update)) {
@@ -177,7 +177,7 @@ private LocalDateTime getDateTime(ResultSet rs, String column) throws Exception
177177
}
178178

179179
@Override
180-
public void scheduleTask(CopyContext context, CopyContext.DataCopyItem copyItem, long sourceRowCount,
180+
public synchronized void scheduleTask(CopyContext context, CopyContext.DataCopyItem copyItem, long sourceRowCount,
181181
int targetNode) throws Exception {
182182
String insert = "INSERT INTO " + TABLECOPYTASKS
183183
+ " (targetnodeid, pipelinename, sourcetablename, targettablename, columnmap, migrationid, sourcerowcount, lastupdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
@@ -195,7 +195,7 @@ public void scheduleTask(CopyContext context, CopyContext.DataCopyItem copyItem,
195195
}
196196

197197
@Override
198-
public void rescheduleTask(CopyContext context, String pipelineName, int targetNode) throws Exception {
198+
public synchronized void rescheduleTask(CopyContext context, String pipelineName, int targetNode) throws Exception {
199199
String sql = "UPDATE " + TABLECOPYTASKS
200200
+ " SET failure='0', duration=NULL, error='', targetnodeid=?, lastupdate=? WHERE migrationId=? AND pipelinename=? ";
201201
try (Connection connection = getConnection(context);
@@ -209,8 +209,8 @@ public void rescheduleTask(CopyContext context, String pipelineName, int targetN
209209
}
210210

211211
@Override
212-
public void scheduleBatch(CopyContext context, CopyContext.DataCopyItem copyItem, int batchId, Object lowerBoundary,
213-
Object upperBoundary) throws Exception {
212+
public synchronized void scheduleBatch(CopyContext context, CopyContext.DataCopyItem copyItem, int batchId,
213+
Object lowerBoundary, Object upperBoundary) throws Exception {
214214
LOG.debug("Schedule Batch for {} with ID {}", copyItem.getPipelineName(), batchId);
215215
String insert = "INSERT INTO " + TABLECOPYBATCHES
216216
+ " (migrationId, batchId, pipelinename, lowerBoundary, upperBoundary) VALUES (?, ?, ?, ?, ?)";
@@ -225,7 +225,7 @@ public void scheduleBatch(CopyContext context, CopyContext.DataCopyItem copyItem
225225
}
226226

227227
@Override
228-
public void markBatchCompleted(CopyContext context, CopyContext.DataCopyItem copyItem, int batchId)
228+
public synchronized void markBatchCompleted(CopyContext context, CopyContext.DataCopyItem copyItem, int batchId)
229229
throws Exception {
230230
LOG.debug("Mark batch completed for {} with ID {}", copyItem.getPipelineName(), batchId);
231231
String insert = "DELETE FROM " + TABLECOPYBATCHES + " WHERE migrationId=? AND batchId=? AND pipelinename=?";
@@ -241,7 +241,8 @@ public void markBatchCompleted(CopyContext context, CopyContext.DataCopyItem cop
241241
}
242242

243243
@Override
244-
public void resetPipelineBatches(CopyContext context, CopyContext.DataCopyItem copyItem) throws Exception {
244+
public synchronized void resetPipelineBatches(CopyContext context, CopyContext.DataCopyItem copyItem)
245+
throws Exception {
245246
String insert = "DELETE FROM " + TABLECOPYBATCHES + " WHERE migrationId=? AND pipelinename=?";
246247
try (Connection conn = getConnection(context); PreparedStatement stmt = conn.prepareStatement(insert)) {
247248
stmt.setObject(1, context.getMigrationId());
@@ -335,7 +336,7 @@ public Set<DatabaseCopyTask> findFailedTasks(CopyContext context) throws Excepti
335336
}
336337

337338
@Override
338-
public void updateTaskProgress(CopyContext context, CopyContext.DataCopyItem copyItem, long itemCount)
339+
public synchronized void updateTaskProgress(CopyContext context, CopyContext.DataCopyItem copyItem, long itemCount)
339340
throws Exception {
340341
String sql = "UPDATE " + TABLECOPYTASKS
341342
+ " SET targetrowcount=?, lastupdate=?, avgwriterrowthroughput=?, avgreaderrowthroughput=? WHERE targetnodeid=? AND migrationid=? AND pipelinename=?";
@@ -362,7 +363,7 @@ public void markTaskCompleted(final CopyContext context, final CopyContext.DataC
362363
}
363364

364365
@Override
365-
public void markTaskCompleted(final CopyContext context, final CopyContext.DataCopyItem copyItem,
366+
public synchronized void markTaskCompleted(final CopyContext context, final CopyContext.DataCopyItem copyItem,
366367
final String duration, final float durationseconds) throws Exception {
367368
Objects.requireNonNull(duration, "duration must not be null");
368369
// spotless:off
@@ -384,7 +385,7 @@ public void markTaskCompleted(final CopyContext context, final CopyContext.DataC
384385
}
385386

386387
@Override
387-
public void markTaskFailed(CopyContext context, CopyContext.DataCopyItem copyItem, Exception error)
388+
public synchronized void markTaskFailed(CopyContext context, CopyContext.DataCopyItem copyItem, Exception error)
388389
throws Exception {
389390
// spotless:off
390391
String sql = "UPDATE " + TABLECOPYTASKS + " SET failure='1', duration='-1', error=?, lastupdate=? WHERE targetnodeid=? AND migrationId=? AND pipelinename=? AND failure = '0'";
@@ -406,7 +407,8 @@ public void markTaskFailed(CopyContext context, CopyContext.DataCopyItem copyIte
406407
}
407408

408409
@Override
409-
public void markTaskTruncated(CopyContext context, CopyContext.DataCopyItem copyItem) throws Exception {
410+
public synchronized void markTaskTruncated(CopyContext context, CopyContext.DataCopyItem copyItem)
411+
throws Exception {
410412
String sql = "UPDATE " + TABLECOPYTASKS
411413
+ " SET truncated = '1' WHERE targetnodeid=? AND migrationId=? AND pipelinename=? ";
412414
try (Connection connection = getConnection(context);
@@ -419,8 +421,8 @@ public void markTaskTruncated(CopyContext context, CopyContext.DataCopyItem copy
419421
}
420422

421423
@Override
422-
public void updateTaskCopyMethod(CopyContext context, CopyContext.DataCopyItem copyItem, String copyMethod)
423-
throws Exception {
424+
public synchronized void updateTaskCopyMethod(CopyContext context, CopyContext.DataCopyItem copyItem,
425+
String copyMethod) throws Exception {
424426
String sql = "UPDATE " + TABLECOPYTASKS
425427
+ " SET copymethod=? WHERE targetnodeid=? AND migrationId=? AND pipelinename=? ";
426428
try (Connection connection = getConnection(context);
@@ -434,7 +436,7 @@ public void updateTaskCopyMethod(CopyContext context, CopyContext.DataCopyItem c
434436
}
435437

436438
@Override
437-
public void updateTaskKeyColumns(CopyContext context, CopyContext.DataCopyItem copyItem,
439+
public synchronized void updateTaskKeyColumns(CopyContext context, CopyContext.DataCopyItem copyItem,
438440
Collection<String> keyColumns) throws Exception {
439441
String sql = "UPDATE " + TABLECOPYTASKS
440442
+ " SET keycolumns=? WHERE targetnodeid=? AND migrationId=? AND pipelinename=? ";

commercedbsynchac/hac/resources/jsp/dataCopy.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</hac:note>
3939
<span id="timezoneCheckboxContainer"><input type="checkbox" id="timezoneCheckbox" name="timezoneCheckbox" onchange="document.getElementById('buttonCopyData').disabled=!this.checked"> I am aware of timezone differences, proceed with migration</span>
4040
</c:if>
41-
<div class="clearfix">
41+
<div class="clearfix" id="buttonsContainer" data-resumeUrl="<c:url value="/commercedbsynchac/resumeRunning"/>">
4242
<button id="buttonCopyData" class="control-button" data-url="<c:url value="/commercedbsynchac/copyData"/>">Start</button>
4343
<button id="buttonStopCopyData" class="control-button" data-url="<c:url value="/commercedbsynchac/abortCopy"/>">Stop</button>
4444
</div>

commercedbsynchac/hac/resources/jsp/migrationReports.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<button id="toggleSidebarButton">&gt;</button>
2727
<div class="marginLeft marginBottom">
2828
<h2>Migration Reports</h2>
29-
<div id="reportsWrapper">
29+
<div id="reportsWrapper" data-url="<c:url value="/commercedbsynchac/loadMigrationReports"/>" data-downloadUrl="<c:url value="/commercedbsynchac/downloadLogsReport"/>">
3030
<table id="reportsTable">
3131
<thead>
3232
<tr>

commercedbsynchac/hac/resources/jsp/schemaCopy.jsp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
<title>Copy Schema To SAP Commerce Cloud</title>
1313
<link rel="stylesheet" href="<c:url value="/static/css/table.css"/>" type="text/css" media="screen, projection" />
1414
<link rel="stylesheet" href="<c:url value="/static/css/database.css"/>" type="text/css" media="screen, projection" />
15-
<link rel="stylesheet" href="<c:url value="/static/css/codemirror3/codemirror.css"/>" type="text/css" media="screen, projection" />
1615
<link rel="stylesheet" href="<c:url value="/static/css/schemaCopy.css"/>" type="text/css" media="screen, projection" />
16+
<link rel="stylesheet" href="<c:url value="/static/css/console/codemirror3-custom.css"/>" type="text/css" media="screen, projection" />
17+
<link rel="stylesheet" href="<c:url value="${useCodeMirrorWebJar ? '/webjars/codemirror/lib' : '/static/css/codemirror3'}/codemirror.css"/>" type="text/css" media="screen, projection" />
1718

1819

1920
<script type="text/javascript" src="<c:url value="/static/js/jquery.dataTables.min.js"/>"></script>
2021
<script type="text/javascript" src="<c:url value="/static/js/history.js"/>"></script>
2122
<script type="text/javascript" src="<c:url value="/static/js/schemaCopy.js"/>"></script>
22-
<script type="text/javascript" src="<c:url value="/static/js/codemirror3/codemirror.js"/>"></script>
23-
<script type="text/javascript" src="<c:url value="/static/js/codemirror3/sql.js"/>"></script>
23+
<script type="text/javascript" src="<c:url value="${useCodeMirrorWebJar ? '/webjars/codemirror/lib' : '/static/js/codemirror3'}/codemirror.js"/>"></script>
24+
<script type="text/javascript" src="<c:url value="${useCodeMirrorWebJar ? '/webjars/codemirror/mode/sql' : '/static/js/codemirror3'}/sql.js"/>"></script>
2425
</head>
2526
<body>
2627
<div class="prepend-top span-17 colborder" id="content">

0 commit comments

Comments
 (0)