use of com.datastax.oss.dsbulk.connectors.api.Record in project dsbulk by datastax.
the class LogManager method appendUnmappableStatementToDebugFile.
// Mapping errors (failed record -> statement or row -> record mappings)
// record -> statement failed (load workflow)
@SuppressWarnings("BlockingMethodInNonBlockingContext")
private Mono<UnmappableStatement> appendUnmappableStatementToDebugFile(UnmappableStatement statement) {
try {
Path logFile = operationDirectory.resolve(MAPPING_ERRORS_FILE);
PrintWriter writer = openFiles.get(logFile);
assert writer != null;
Record record = statement.getRecord();
writer.println("Resource: " + record.getResource());
writer.println("Position: " + record.getPosition());
if (record.getSource() != null) {
writer.println("Source: " + LogManagerUtils.formatSource(record));
}
stackTracePrinter.printStackTrace(statement.getError(), writer);
writer.println();
writer.flush();
return Mono.just(statement);
} catch (Exception e) {
return Mono.error(e);
}
}
use of com.datastax.oss.dsbulk.connectors.api.Record in project dsbulk by datastax.
the class UnloadWorkflow method oneWriter.
private Flux<Record> oneWriter() {
int numThreads = Math.min(numCores * 2, readConcurrency);
Scheduler scheduler = numThreads == 1 ? Schedulers.immediate() : Schedulers.newParallel(numThreads, new DefaultThreadFactory("workflow"));
schedulers.add(scheduler);
return Flux.fromIterable(readStatements).flatMap(results -> Flux.from(executor.readReactive(results)).publishOn(scheduler, 500).transform(queryWarningsHandler).transform(totalItemsMonitor).transform(totalItemsCounter).transform(failedReadResultsMonitor).transform(failedReadsHandler).map(readResultMapper::map).transform(failedRecordsMonitor).transform(unmappableRecordsHandler), readConcurrency, 500).transform(writer).transform(failedRecordsMonitor).transform(failedRecordsHandler);
}
use of com.datastax.oss.dsbulk.connectors.api.Record in project dsbulk by datastax.
the class LogManagerTest method should_handle_failed_records_without_source.
@Test
void should_handle_failed_records_without_source() throws Exception {
Path outputDir = Files.createTempDirectory("test");
LogManager logManager = new LogManager(session, outputDir, ErrorThreshold.forAbsoluteValue(1), ErrorThreshold.forAbsoluteValue(0), true, statementFormatter, EXTENDED, rowFormatter);
logManager.init();
Record record = new DefaultErrorRecord(null, resource1, 1, new RuntimeException("error 1"));
Flux<Record> stmts = Flux.just(record);
stmts.transform(logManager.newFailedRecordsHandler()).blockLast();
logManager.close();
Path errors = logManager.getOperationDirectory().resolve("connector-errors.log");
Path positions = logManager.getOperationDirectory().resolve("positions.txt");
assertThat(errors.toFile()).exists();
assertThat(positions.toFile()).exists();
assertThat(FileUtils.listAllFilesInDirectory(logManager.getOperationDirectory())).containsOnly(errors, positions);
List<String> lines = Files.readAllLines(errors, UTF_8);
String content = String.join("\n", lines);
assertThat(content).doesNotContain("Source: ").contains("Resource: " + resource1).contains("java.lang.RuntimeException: error 1");
List<String> positionLines = Files.readAllLines(positions, UTF_8);
assertThat(positionLines).containsOnly("file:///file1.csv:1");
}
use of com.datastax.oss.dsbulk.connectors.api.Record in project dsbulk by datastax.
the class LogManagerTest method should_handle_unmappable_records_without_source.
@Test
void should_handle_unmappable_records_without_source() throws Exception {
Path outputDir = Files.createTempDirectory("test");
LogManager logManager = new LogManager(session, outputDir, ErrorThreshold.forAbsoluteValue(1), ErrorThreshold.forAbsoluteValue(0), true, statementFormatter, EXTENDED, rowFormatter);
logManager.init();
Record record = new DefaultErrorRecord(null, tableResource, 1, new RuntimeException("error 1"));
Flux<Record> stmts = Flux.just(record);
stmts.transform(logManager.newUnmappableRecordsHandler()).blockLast();
logManager.close();
Path errors = logManager.getOperationDirectory().resolve("mapping-errors.log");
assertThat(errors.toFile()).exists();
assertThat(FileUtils.listAllFilesInDirectory(logManager.getOperationDirectory())).containsOnly(errors);
List<String> lines = Files.readAllLines(errors, UTF_8);
String content = String.join("\n", lines);
assertThat(content).doesNotContain("Source: ").doesNotContain("Resource: ").doesNotContain("Position: ").contains("java.lang.RuntimeException: error 1");
}
use of com.datastax.oss.dsbulk.connectors.api.Record in project dsbulk by datastax.
the class LogManagerTest method should_print_raw_bytes_when_column_cannot_be_properly_deserialized.
@Test
void should_print_raw_bytes_when_column_cannot_be_properly_deserialized() throws Exception {
Path outputDir = Files.createTempDirectory("test");
LogManager logManager = new LogManager(session, outputDir, ErrorThreshold.forAbsoluteValue(2), ErrorThreshold.forAbsoluteValue(0), true, statementFormatter, EXTENDED, rowFormatter);
// Emulate bad row with corrupted data, see DefaultReadResultMapper
IllegalArgumentException cause = new IllegalArgumentException("Invalid 32-bits integer value, expecting 4 bytes but got 5");
IllegalArgumentException iae = new IllegalArgumentException("Could not deserialize column c1 of type int as java.lang.Integer", cause);
when(row1.getObject(0)).thenThrow(cause);
when(row1.getBytesUnsafe(0)).thenReturn(ByteBuffer.wrap(new byte[] { 1, 2, 3, 4, 5 }));
rowRecord1 = new DefaultErrorRecord(successfulReadResult1, tableResource, 1, iae);
logManager.init();
Flux<Record> stmts = Flux.just(rowRecord1);
stmts.transform(logManager.newUnmappableRecordsHandler()).blockLast();
logManager.close();
Path errors = logManager.getOperationDirectory().resolve("mapping-errors.log");
assertThat(errors.toFile()).exists();
assertThat(FileUtils.listAllFilesInDirectory(logManager.getOperationDirectory())).containsOnly(errors);
List<String> lines = Files.readAllLines(errors, UTF_8);
String content = String.join("\n", lines);
assertThat(content).doesNotContain("Resource: ").doesNotContain("Position: ").contains("SELECT 1").contains("c1: 0x0102030405 (malformed buffer for type INT)").contains(iae.getMessage()).contains(cause.getMessage());
}
Aggregations