Skip to content

Commit 6980703

Browse files
committed
Initial commit
1 parent 1e10da9 commit 6980703

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataimport/ImportCommand.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import java.util.Optional;
4141
import java.util.concurrent.Callable;
4242
import org.apache.commons.lang3.StringUtils;
43+
import org.slf4j.Logger;
44+
import org.slf4j.LoggerFactory;
4345
import picocli.CommandLine;
4446
import picocli.CommandLine.Model.CommandSpec;
4547
import picocli.CommandLine.ParameterException;
@@ -48,13 +50,16 @@
4850
@CommandLine.Command(name = "import", description = "Import data into a ScalarDB table")
4951
public class ImportCommand extends ImportCommandOptions implements Callable<Integer> {
5052

53+
private static final Logger logger = LoggerFactory.getLogger(ImportCommand.class);
54+
5155
/** Spec injected by PicoCli */
5256
@Spec CommandSpec spec;
5357

5458
@Override
5559
public Integer call() throws Exception {
5660
validateDeprecatedOptions();
5761
applyDeprecatedOptions();
62+
warnAboutIgnoredDeprecatedOptions();
5863
validateImportTarget(controlFilePath, namespace, tableName);
5964
validateLogDirectory(logDirectory);
6065
validatePositiveValue(
@@ -279,6 +284,28 @@ private Optional<ControlFile> parseControlFileFromPath(String controlFilePath) {
279284
spec.commandLine(), DataLoaderError.INVALID_CONTROL_FILE.buildMessage(controlFilePath));
280285
}
281286
}
287+
/** Warns about deprecated options that are no longer used and have been completely ignored. */
288+
private void warnAboutIgnoredDeprecatedOptions() {
289+
CommandLine.ParseResult parseResult = spec.commandLine().getParseResult();
290+
boolean hasRawRecordOption =
291+
parseResult.hasMatchedOption(DEPRECATED_LOG_RAW_RECORDS_OPTION)
292+
|| parseResult.hasMatchedOption(DEPRECATED_LOG_RAW_RECORDS_OPTION_SHORT);
293+
294+
if (hasRawRecordOption) {
295+
// Use picocli's ANSI support for colored warning output
296+
CommandLine.Help.Ansi ansi = CommandLine.Help.Ansi.AUTO;
297+
String warning =
298+
ansi.string(
299+
"@|bold,yellow The "
300+
+ DEPRECATED_LOG_RAW_RECORDS_OPTION
301+
+ " option is deprecated and no longer has any effect. "
302+
+ "This option is no longer required because failure records are "
303+
+ "always logged by default.|@");
304+
305+
logger.warn(warning);
306+
}
307+
}
308+
282309

283310
/**
284311
* Validates that deprecated and new options are not both specified.

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataimport/ImportCommandOptions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class ImportCommandOptions {
1616
public static final String ENABLE_LOG_SUCCESS_RECORDS_OPTION = "--enable-log-success";
1717
public static final String ENABLE_LOG_SUCCESS_RECORDS_OPTION_SHORT = "-ls";
1818
public static final String DEPRECATED_LOG_SUCCESS_RECORDS_OPTION = "--log-success";
19+
public static final String DEPRECATED_LOG_RAW_RECORDS_OPTION_SHORT = "-lr";
20+
public static final String DEPRECATED_LOG_RAW_RECORDS_OPTION = "--log-raw-record";
1921

2022
@CommandLine.Option(
2123
names = {"--mode", "-m"},
@@ -123,6 +125,11 @@ public class ImportCommandOptions {
123125
defaultValue = "false")
124126
protected boolean ignoreNullValues;
125127

128+
/**
129+
* @deprecated As of release 3.6.2. This option is no longer required because failure records are
130+
* always logged by default. It will be removed in release 4.0.0.
131+
*/
132+
@Deprecated
126133
@CommandLine.Option(
127134
names = {"--log-raw-record", "-lr"},
128135
description = "Include the original source record in the log file output (default: false)",

data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataimport/log/SingleFileImportLogger.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public SingleFileImportLogger(ImportLoggerConfig config, LogWriterFactory logWri
7474
*/
7575
@Override
7676
public void onTaskComplete(ImportTaskResult taskResult) {
77-
if (!config.isLogSuccessRecordsEnabled() && !config.isLogRawSourceRecordsEnabled()) return;
7877
try {
7978
writeImportTaskResultDetailToLogs(taskResult);
8079
} catch (Exception e) {
@@ -199,9 +198,7 @@ private void writeImportTaskResultDetailToLogs(ImportTaskResult importTaskResult
199198
&& target.getStatus().equals(ImportTargetResultStatus.SAVED)) {
200199

201200
writeToLogWriter(successLogWriter, OBJECT_MAPPER.valueToTree(target));
202-
}
203-
if (config.isLogRawSourceRecordsEnabled()
204-
&& !target.getStatus().equals(ImportTargetResultStatus.SAVED)) {
201+
} else if (!target.getStatus().equals(ImportTargetResultStatus.SAVED)) {
205202
writeToLogWriter(failureLogWriter, OBJECT_MAPPER.valueToTree(target));
206203
}
207204
}

data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataimport/log/SplitByDataChunkImportLogger.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ private void writeImportTaskResultDetailToLogs(ImportTaskResult importTaskResult
9494
ImportTargetResultStatus status = target.getStatus();
9595
if (status.equals(ImportTargetResultStatus.SAVED) && config.isLogSuccessRecordsEnabled()) {
9696
writeLog(target, LogFileType.SUCCESS, importTaskResult.getDataChunkId());
97-
} else if (!status.equals(ImportTargetResultStatus.SAVED)
98-
&& config.isLogRawSourceRecordsEnabled()) {
97+
} else if (!status.equals(ImportTargetResultStatus.SAVED)) {
9998
writeLog(target, LogFileType.FAILURE, importTaskResult.getDataChunkId());
10099
}
101100
}

0 commit comments

Comments
 (0)