CodeStyle formatting to conform to basic Checkstyle rules.
The code-style rules follow google style with some changes: 1. Increase line length from 100 to 120 2. Disable JavaDoc related checkstyles as this needs more manual work. Both source and test code are checked for code-style
This commit is contained in:
committed by
vinoth chandar
parent
987f5d6b96
commit
788e4f2d2e
@@ -24,11 +24,6 @@ import com.uber.hoodie.exception.HoodieException;
|
||||
import com.uber.hoodie.io.HoodieCreateHandle;
|
||||
import com.uber.hoodie.io.HoodieIOHandle;
|
||||
import com.uber.hoodie.table.HoodieTable;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.spark.TaskContext;
|
||||
import org.apache.spark.TaskContext$;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -38,6 +33,10 @@ import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.spark.TaskContext;
|
||||
import org.apache.spark.TaskContext$;
|
||||
|
||||
/**
|
||||
* Lazy Iterable, that writes a stream of HoodieRecords sorted by the partitionPath, into new
|
||||
@@ -68,35 +67,37 @@ public class LazyInsertIterable<T extends HoodieRecordPayload> extends
|
||||
|
||||
@Override
|
||||
protected List<WriteStatus> computeNext() {
|
||||
// Need to set current spark thread's TaskContext into newly launched thread so that new thread can access
|
||||
// Need to set current spark thread's TaskContext into newly launched thread so that new
|
||||
// thread can access
|
||||
// TaskContext properties.
|
||||
final TaskContext sparkThreadTaskContext = TaskContext.get();
|
||||
// Executor service used for launching writer thread.
|
||||
final ExecutorService writerService = Executors.newFixedThreadPool(1);
|
||||
try {
|
||||
// Used for buffering records which is controlled by HoodieWriteConfig#WRITE_BUFFER_LIMIT_BYTES.
|
||||
final BufferedIterator<T, HoodieRecord<T>> bufferedIterator =
|
||||
new BufferedIterator<>(inputItr, hoodieConfig.getWriteBufferLimitBytes(),
|
||||
HoodieIOHandle.createHoodieWriteSchema(hoodieConfig));
|
||||
Future<List<WriteStatus>> writerResult =
|
||||
writerService.submit(
|
||||
() -> {
|
||||
logger.info("starting hoodie writer thread");
|
||||
// Passing parent thread's TaskContext to newly launched thread for it to access original TaskContext
|
||||
// properties.
|
||||
TaskContext$.MODULE$.setTaskContext(sparkThreadTaskContext);
|
||||
List<WriteStatus> statuses = new LinkedList<>();
|
||||
try {
|
||||
statuses.addAll(handleWrite(bufferedIterator));
|
||||
logger.info("hoodie write is done; notifying reader thread");
|
||||
return statuses;
|
||||
} catch (Exception e) {
|
||||
logger.error("error writing hoodie records", e);
|
||||
bufferedIterator.markAsFailed(e);
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
// Buffering records into internal buffer. This can throw exception either if reading records from spark fails or
|
||||
// Used for buffering records which is controlled by
|
||||
// HoodieWriteConfig#WRITE_BUFFER_LIMIT_BYTES.
|
||||
final BufferedIterator<T, HoodieRecord<T>> bufferedIterator = new BufferedIterator<>(inputItr,
|
||||
hoodieConfig.getWriteBufferLimitBytes(),
|
||||
HoodieIOHandle.createHoodieWriteSchema(hoodieConfig));
|
||||
Future<List<WriteStatus>> writerResult = writerService.submit(() -> {
|
||||
logger.info("starting hoodie writer thread");
|
||||
// Passing parent thread's TaskContext to newly launched thread for it to access original
|
||||
// TaskContext
|
||||
// properties.
|
||||
TaskContext$.MODULE$.setTaskContext(sparkThreadTaskContext);
|
||||
List<WriteStatus> statuses = new LinkedList<>();
|
||||
try {
|
||||
statuses.addAll(handleWrite(bufferedIterator));
|
||||
logger.info("hoodie write is done; notifying reader thread");
|
||||
return statuses;
|
||||
} catch (Exception e) {
|
||||
logger.error("error writing hoodie records", e);
|
||||
bufferedIterator.markAsFailed(e);
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
// Buffering records into internal buffer. This can throw exception either if reading
|
||||
// records from spark fails or
|
||||
// if writing buffered records into parquet file fails.
|
||||
bufferedIterator.startBuffering();
|
||||
logger.info("waiting for hoodie write to finish");
|
||||
@@ -110,28 +111,27 @@ public class LazyInsertIterable<T extends HoodieRecordPayload> extends
|
||||
}
|
||||
}
|
||||
|
||||
private List<WriteStatus> handleWrite(final BufferedIterator<T, HoodieRecord<T>> bufferedIterator) {
|
||||
private List<WriteStatus> handleWrite(
|
||||
final BufferedIterator<T, HoodieRecord<T>> bufferedIterator) {
|
||||
List<WriteStatus> statuses = new ArrayList<>();
|
||||
while (bufferedIterator.hasNext()) {
|
||||
final BufferedIterator.BufferedIteratorPayload<HoodieRecord<T>> payload = bufferedIterator.next();
|
||||
final BufferedIterator.BufferedIteratorPayload<HoodieRecord<T>> payload = bufferedIterator
|
||||
.next();
|
||||
|
||||
// clean up any partial failures
|
||||
if (!partitionsCleaned.contains(payload.record.getPartitionPath())) {
|
||||
// This insert task could fail multiple times, but Spark will faithfully retry with
|
||||
// the same data again. Thus, before we open any files under a given partition, we
|
||||
// first delete any files in the same partitionPath written by same Spark partition
|
||||
HoodieIOHandle.cleanupTmpFilesFromCurrentCommit(hoodieConfig,
|
||||
commitTime,
|
||||
payload.record.getPartitionPath(),
|
||||
TaskContext.getPartitionId(),
|
||||
hoodieTable);
|
||||
HoodieIOHandle.cleanupTmpFilesFromCurrentCommit(hoodieConfig, commitTime,
|
||||
payload.record.getPartitionPath(), TaskContext.getPartitionId(), hoodieTable);
|
||||
partitionsCleaned.add(payload.record.getPartitionPath());
|
||||
}
|
||||
|
||||
// lazily initialize the handle, for the first time
|
||||
if (handle == null) {
|
||||
handle =
|
||||
new HoodieCreateHandle(hoodieConfig, commitTime, hoodieTable, payload.record.getPartitionPath());
|
||||
handle = new HoodieCreateHandle(hoodieConfig, commitTime, hoodieTable,
|
||||
payload.record.getPartitionPath());
|
||||
}
|
||||
|
||||
if (handle.canWrite(payload.record)) {
|
||||
@@ -141,9 +141,10 @@ public class LazyInsertIterable<T extends HoodieRecordPayload> extends
|
||||
// handle is full.
|
||||
statuses.add(handle.close());
|
||||
// Need to handle the rejected payload & open new handle
|
||||
handle =
|
||||
new HoodieCreateHandle(hoodieConfig, commitTime, hoodieTable, payload.record.getPartitionPath());
|
||||
handle.write(payload.record, payload.insertValue, payload.exception); // we should be able to write 1 payload.
|
||||
handle = new HoodieCreateHandle(hoodieConfig, commitTime, hoodieTable,
|
||||
payload.record.getPartitionPath());
|
||||
handle.write(payload.record, payload.insertValue,
|
||||
payload.exception); // we should be able to write 1 payload.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user