Search in sources :

Example 1 with WriteMetadataEvent

use of org.apache.hudi.sink.event.WriteMetadataEvent in project hudi by apache.

the class BulkInsertWriteFunction method sendBootstrapEvent.

private void sendBootstrapEvent() {
    WriteMetadataEvent event = WriteMetadataEvent.builder().taskID(taskID).writeStatus(Collections.emptyList()).instantTime("").bootstrap(true).build();
    this.eventGateway.sendEventToCoordinator(event);
    LOG.info("Send bootstrap write metadata event to coordinator, task[{}].", taskID);
}
Also used : WriteMetadataEvent(org.apache.hudi.sink.event.WriteMetadataEvent)

Example 2 with WriteMetadataEvent

use of org.apache.hudi.sink.event.WriteMetadataEvent in project hudi by apache.

the class AbstractStreamWriteFunction method reloadWriteMetaState.

/**
 * Reload the write metadata state as the current checkpoint.
 */
private void reloadWriteMetaState() throws Exception {
    this.writeMetadataState.clear();
    WriteMetadataEvent event = WriteMetadataEvent.builder().taskID(taskID).instantTime(currentInstant).writeStatus(new ArrayList<>(writeStatuses)).bootstrap(true).build();
    this.writeMetadataState.add(event);
    writeStatuses.clear();
}
Also used : WriteMetadataEvent(org.apache.hudi.sink.event.WriteMetadataEvent)

Example 3 with WriteMetadataEvent

use of org.apache.hudi.sink.event.WriteMetadataEvent in project hudi by apache.

the class StreamWriteFunction method flushRemaining.

@SuppressWarnings("unchecked, rawtypes")
private void flushRemaining(boolean endInput) {
    this.currentInstant = instantToWrite(hasData());
    if (this.currentInstant == null) {
        // in case there are empty checkpoints that has no input data
        throw new HoodieException("No inflight instant when flushing data!");
    }
    final List<WriteStatus> writeStatus;
    if (buckets.size() > 0) {
        writeStatus = new ArrayList<>();
        this.buckets.values().forEach(bucket -> {
            List<HoodieRecord> records = bucket.writeBuffer();
            if (records.size() > 0) {
                if (config.getBoolean(FlinkOptions.PRE_COMBINE)) {
                    records = FlinkWriteHelper.newInstance().deduplicateRecords(records, (HoodieIndex) null, -1);
                }
                bucket.preWrite(records);
                writeStatus.addAll(writeFunction.apply(records, currentInstant));
                records.clear();
                bucket.reset();
            }
        });
    } else {
        LOG.info("No data to write in subtask [{}] for instant [{}]", taskID, currentInstant);
        writeStatus = Collections.emptyList();
    }
    final WriteMetadataEvent event = WriteMetadataEvent.builder().taskID(taskID).instantTime(currentInstant).writeStatus(writeStatus).lastBatch(true).endInput(endInput).build();
    this.eventGateway.sendEventToCoordinator(event);
    this.buckets.clear();
    this.tracer.reset();
    this.writeClient.cleanHandles();
    this.writeStatuses.addAll(writeStatus);
    // blocks flushing until the coordinator starts a new instant
    this.confirming = true;
}
Also used : HoodieIndex(org.apache.hudi.index.HoodieIndex) HoodieRecord(org.apache.hudi.common.model.HoodieRecord) HoodieException(org.apache.hudi.exception.HoodieException) WriteMetadataEvent(org.apache.hudi.sink.event.WriteMetadataEvent) WriteStatus(org.apache.hudi.client.WriteStatus)

Example 4 with WriteMetadataEvent

use of org.apache.hudi.sink.event.WriteMetadataEvent in project hudi by apache.

the class StreamWriteOperatorCoordinator method handleEventFromOperator.

@Override
public void handleEventFromOperator(int i, OperatorEvent operatorEvent) {
    ValidationUtils.checkState(operatorEvent instanceof WriteMetadataEvent, "The coordinator can only handle WriteMetaEvent");
    WriteMetadataEvent event = (WriteMetadataEvent) operatorEvent;
    if (event.isEndInput()) {
        // handle end input event synchronously
        handleEndInputEvent(event);
    } else {
        executor.execute(() -> {
            if (event.isBootstrap()) {
                handleBootstrapEvent(event);
            } else {
                handleWriteMetaEvent(event);
            }
        }, "handle write metadata event for instant %s", this.instant);
    }
}
Also used : WriteMetadataEvent(org.apache.hudi.sink.event.WriteMetadataEvent)

Example 5 with WriteMetadataEvent

use of org.apache.hudi.sink.event.WriteMetadataEvent in project hudi by apache.

the class AppendWriteFunction method flushData.

private void flushData(boolean endInput) {
    final List<WriteStatus> writeStatus;
    final String instant;
    if (this.writerHelper != null) {
        writeStatus = this.writerHelper.getWriteStatuses(this.taskID);
        instant = this.writerHelper.getInstantTime();
    } else {
        LOG.info("No data to write in subtask [{}] for instant [{}]", taskID, currentInstant);
        writeStatus = Collections.emptyList();
        instant = instantToWrite(false);
    }
    final WriteMetadataEvent event = WriteMetadataEvent.builder().taskID(taskID).instantTime(instant).writeStatus(writeStatus).lastBatch(true).endInput(endInput).build();
    this.eventGateway.sendEventToCoordinator(event);
    // nullify the write helper for next ckp
    this.writerHelper = null;
    this.writeStatuses.addAll(writeStatus);
    // blocks flushing until the coordinator starts a new instant
    this.confirming = true;
}
Also used : WriteMetadataEvent(org.apache.hudi.sink.event.WriteMetadataEvent) WriteStatus(org.apache.hudi.client.WriteStatus)

Aggregations

WriteMetadataEvent (org.apache.hudi.sink.event.WriteMetadataEvent)10 WriteStatus (org.apache.hudi.client.WriteStatus)4 Configuration (org.apache.flink.configuration.Configuration)2 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)2 MockOperatorCoordinatorContext (org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext)2 OperatorCoordinator (org.apache.flink.runtime.operators.coordination.OperatorCoordinator)2 HoodieRecord (org.apache.hudi.common.model.HoodieRecord)2 HoodieIndex (org.apache.hudi.index.HoodieIndex)2 MockCoordinatorExecutor (org.apache.hudi.sink.utils.MockCoordinatorExecutor)2 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 HoodieTableMetaClient (org.apache.hudi.common.table.HoodieTableMetaClient)1 HoodieTimeline (org.apache.hudi.common.table.timeline.HoodieTimeline)1 HoodieException (org.apache.hudi.exception.HoodieException)1