Skip to content

Commit 4989d9d

Browse files
committed
Log warning if --include-metadata is used
1 parent c44db24 commit 4989d9d

File tree

5 files changed

+154
-8
lines changed

5 files changed

+154
-8
lines changed

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataexport/ExportCommand.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class ExportCommand extends ExportCommandOptions implements Callable<Inte
5555
public Integer call() throws Exception {
5656
validateDeprecatedOptions();
5757
applyDeprecatedOptions();
58+
warnAboutIgnoredDeprecatedOptions();
5859
String scalarDbPropertiesFilePath = getScalarDbPropertiesFilePath();
5960

6061
try {
@@ -142,6 +143,29 @@ private void validateDeprecatedOptions() {
142143
MAX_THREADS_OPTION_SHORT);
143144
}
144145

146+
/** Warns about deprecated options that are no longer used and have been completely ignored. */
147+
private void warnAboutIgnoredDeprecatedOptions() {
148+
boolean hasIncludeMetadata =
149+
spec.commandLine().getParseResult().hasMatchedOption(DEPRECATED_INCLUDE_METADATA_OPTION)
150+
|| spec.commandLine()
151+
.getParseResult()
152+
.hasMatchedOption(DEPRECATED_INCLUDE_METADATA_OPTION_SHORT);
153+
154+
if (hasIncludeMetadata) {
155+
// Use picocli's ANSI support for colored warning output
156+
CommandLine.Help.Ansi ansi = CommandLine.Help.Ansi.AUTO;
157+
String warning =
158+
ansi.string(
159+
"@|bold,yellow The "
160+
+ DEPRECATED_INCLUDE_METADATA_OPTION
161+
+ " option is deprecated and no longer has any effect. "
162+
+ "Use the 'scalar.db.consensus_commit.include_metadata.enabled' configuration property "
163+
+ "in your ScalarDB properties file to control whether transaction metadata is included in full scans.|@");
164+
165+
logger.warn(warning);
166+
}
167+
}
168+
145169
private String getScalarDbPropertiesFilePath() {
146170
if (StringUtils.isBlank(configFilePath)) {
147171
throw new IllegalArgumentException(DataLoaderError.CONFIG_FILE_PATH_BLANK.buildMessage());
@@ -161,8 +185,7 @@ private void validateOutputDirectory() throws DirectoryValidationException {
161185

162186
private ExportManager createExportManager(
163187
TransactionFactory transactionFactory, ScalarDbDao scalarDbDao, FileFormat fileFormat) {
164-
ProducerTaskFactory taskFactory =
165-
new ProducerTaskFactory(delimiter, prettyPrintJson);
188+
ProducerTaskFactory taskFactory = new ProducerTaskFactory(delimiter, prettyPrintJson);
166189
DistributedTransactionManager manager = transactionFactory.getTransactionManager();
167190
switch (fileFormat) {
168191
case JSON:

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataexport/ExportCommandOptions.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class ExportCommandOptions {
1919
public static final String MAX_THREADS_OPTION = "--max-threads";
2020
public static final String MAX_THREADS_OPTION_SHORT = "-mt";
2121
public static final String DEPRECATED_THREADS_OPTION = "--threads";
22+
public static final String DEPRECATED_INCLUDE_METADATA_OPTION = "--include-metadata";
23+
public static final String DEPRECATED_INCLUDE_METADATA_OPTION_SHORT = "-m";
2224

2325
@CommandLine.Option(
2426
names = {"--config", "-c"},
@@ -70,13 +72,14 @@ public class ExportCommandOptions {
7072
protected FileFormat outputFormat;
7173

7274
/**
73-
* @deprecated As of release 3.16.2 This option is no longer used and will be removed in release
74-
* 4.0.0.
75+
* @deprecated As of release 3.16.2 This option is no longer used and will be removed in release.
76+
* The option is not fully removed as it will break backwards 4.0.0.
7577
*/
7678
@Deprecated
7779
@CommandLine.Option(
7880
names = {"--include-metadata", "-m"},
79-
description = "Deprecated: This option is no longer used",
81+
description =
82+
"Deprecated: This option is no longer used. Please use scalar.db.consensus_commit.include_metadata.enabled to control whether transaction metadata is included in full scans.",
8083
defaultValue = "false",
8184
hidden = true)
8285
protected boolean includeTransactionMetadata;

data-loader/cli/src/test/java/com/scalar/db/dataloader/cli/command/dataexport/ExportCommandTest.java

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,125 @@ void call_withoutMaxThreads_shouldDefaultToAvailableProcessors() {
273273
// Verify it was set to available processors
274274
assertEquals(Runtime.getRuntime().availableProcessors(), command.maxThreads);
275275
}
276+
277+
@Test
278+
void call_withDeprecatedIncludeMetadataOption_shouldParseWithoutError() {
279+
// Simulate command line parsing with deprecated --include-metadata option
280+
String[] args = {
281+
"--config",
282+
"scalardb.properties",
283+
"--namespace",
284+
"scalar",
285+
"--table",
286+
"asset",
287+
"--format",
288+
"JSON",
289+
"--include-metadata"
290+
};
291+
ExportCommand command = new ExportCommand();
292+
CommandLine cmd = new CommandLine(command);
293+
cmd.parseArgs(args);
294+
295+
// Verify the deprecated option was parsed
296+
// Since it has defaultValue = "false", using the flag sets it to true
297+
assertEquals(true, command.includeTransactionMetadata);
298+
299+
// Verify that the spec was set correctly
300+
command.spec = cmd.getCommandSpec();
301+
302+
// Verify that the command line has the deprecated option matched
303+
assertTrue(
304+
cmd.getParseResult()
305+
.hasMatchedOption(ExportCommandOptions.DEPRECATED_INCLUDE_METADATA_OPTION));
306+
}
307+
308+
@Test
309+
void call_withDeprecatedIncludeMetadataShortOption_shouldParseWithoutError() {
310+
// Simulate command line parsing with deprecated -m short option
311+
String[] args = {
312+
"--config",
313+
"scalardb.properties",
314+
"--namespace",
315+
"scalar",
316+
"--table",
317+
"asset",
318+
"--format",
319+
"JSON",
320+
"-m"
321+
};
322+
ExportCommand command = new ExportCommand();
323+
CommandLine cmd = new CommandLine(command);
324+
cmd.parseArgs(args);
325+
326+
// Verify the deprecated option was parsed
327+
assertEquals(true, command.includeTransactionMetadata);
328+
329+
// Verify that the spec was set correctly
330+
command.spec = cmd.getCommandSpec();
331+
332+
// Verify that the command line has the deprecated short option matched
333+
assertTrue(
334+
cmd.getParseResult()
335+
.hasMatchedOption(ExportCommandOptions.DEPRECATED_INCLUDE_METADATA_OPTION_SHORT));
336+
}
337+
338+
@Test
339+
void call_withDeprecatedIncludeMetadataFalse_shouldParseWithoutError() {
340+
// Simulate command line parsing with deprecated --include-metadata=false option
341+
String[] args = {
342+
"--config",
343+
"scalardb.properties",
344+
"--namespace",
345+
"scalar",
346+
"--table",
347+
"asset",
348+
"--format",
349+
"JSON",
350+
"--include-metadata=false"
351+
};
352+
ExportCommand command = new ExportCommand();
353+
CommandLine cmd = new CommandLine(command);
354+
cmd.parseArgs(args);
355+
356+
// Verify the deprecated option was parsed with explicit false value
357+
assertEquals(false, command.includeTransactionMetadata);
358+
359+
// Verify that the spec was set correctly
360+
command.spec = cmd.getCommandSpec();
361+
362+
// Verify that the command line has the deprecated option matched
363+
assertTrue(
364+
cmd.getParseResult()
365+
.hasMatchedOption(ExportCommandOptions.DEPRECATED_INCLUDE_METADATA_OPTION));
366+
}
367+
368+
@Test
369+
void call_withoutDeprecatedIncludeMetadataOption_shouldHaveDefaultValue() {
370+
// Simulate command line parsing without the deprecated option
371+
String[] args = {
372+
"--config",
373+
"scalardb.properties",
374+
"--namespace",
375+
"scalar",
376+
"--table",
377+
"asset",
378+
"--format",
379+
"JSON"
380+
};
381+
ExportCommand command = new ExportCommand();
382+
CommandLine cmd = new CommandLine(command);
383+
cmd.parseArgs(args);
384+
385+
// Verify the option has its default value (false)
386+
assertEquals(false, command.includeTransactionMetadata);
387+
388+
// Verify that the spec was set correctly
389+
command.spec = cmd.getCommandSpec();
390+
391+
// Verify that the command line does NOT have the deprecated option matched
392+
assertEquals(
393+
false,
394+
cmd.getParseResult()
395+
.hasMatchedOption(ExportCommandOptions.DEPRECATED_INCLUDE_METADATA_OPTION));
396+
}
276397
}

data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataexport/ExportManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.scalar.db.dataloader.core.dataexport.validation.ExportOptionsValidator;
1212
import com.scalar.db.dataloader.core.dataimport.dao.ScalarDbDao;
1313
import com.scalar.db.dataloader.core.dataimport.dao.ScalarDbDaoException;
14-
import com.scalar.db.dataloader.core.util.TableMetadataUtil;
1514
import com.scalar.db.exception.transaction.CrudException;
1615
import com.scalar.db.exception.transaction.UnknownTransactionStatusException;
1716
import com.scalar.db.io.DataType;

data-loader/core/src/test/java/com/scalar/db/dataloader/core/dataexport/CsvExportManagerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void startExport_givenValidDataWithoutPartitionKey_shouldGenerateOutputFile()
8888
@Test
8989
void startExport_givenPartitionKey_shouldGenerateOutputFile()
9090
throws IOException, ScalarDbDaoException {
91-
producerTaskFactory = new ProducerTaskFactory(",", false);
91+
producerTaskFactory = new ProducerTaskFactory(",", false);
9292
exportManager = new CsvExportManager(manager, dao, producerTaskFactory);
9393
TransactionManagerCrudOperable.Scanner scanner =
9494
Mockito.mock(TransactionManagerCrudOperable.Scanner.class);
@@ -152,7 +152,7 @@ void startExport_givenHeaderRequired_shouldGenerateOutputFileWithHeader() throws
152152
private void runExportAndAssertFirstLine(boolean excludeHeader, String expectedFirstLine)
153153
throws Exception {
154154
// Arrange
155-
producerTaskFactory = new ProducerTaskFactory(",", false);
155+
producerTaskFactory = new ProducerTaskFactory(",", false);
156156
exportManager = new CsvExportManager(manager, dao, producerTaskFactory);
157157
TransactionManagerCrudOperable.Scanner scanner =
158158
Mockito.mock(TransactionManagerCrudOperable.Scanner.class);

0 commit comments

Comments
 (0)