Implementation:Risingwavelabs Risingwave SinkWriterV1 Interface
Metadata
| Property | Value |
|---|---|
| File | java/connector-node/connector-api/src/main/java/com/risingwave/connector/api/sink/SinkWriterV1.java
|
| Language | Java |
| Module | connector-api |
| Package | com.risingwave.connector.api.sink
|
| Classes | SinkWriterV1 (interface), SinkWriterV1.Adapter (inner class)
|
| Lines | 72 |
Overview
SinkWriterV1 is an older-generation sink writer interface that defines three core operations: write, sync, and drop. It provides a simplified API for sink implementations that do not need to manage epochs or checkpoint metadata directly.
The interface also contains an inner Adapter class that implements the current SinkWriter interface by wrapping a SinkWriterV1 instance. This adapter translates the newer epoch-based and barrier-based API calls into the simpler V1 semantics, providing backward compatibility for legacy sink implementations.
Code Reference
Source Location
java/connector-node/connector-api/src/main/java/com/risingwave/connector/api/sink/SinkWriterV1.java
Signature
public interface SinkWriterV1 {
void write(Iterator<SinkRow> rows);
void sync();
void drop();
class Adapter implements SinkWriter {
public Adapter(SinkWriterV1 inner)
public SinkWriterV1 getInner()
public void beginEpoch(long epoch)
public boolean write(Iterable<SinkRow> rows)
public Optional<ConnectorServiceProto.SinkMetadata> barrier(boolean isCheckpoint)
public void drop()
}
}
Imports
import com.risingwave.proto.ConnectorServiceProto;
import java.util.Iterator;
import java.util.Optional;
I/O Contract
SinkWriterV1 Interface Methods
write
| Parameter | Type | Description |
|---|---|---|
rows |
Iterator<SinkRow> |
An iterator of rows to write to the external sink |
Writes a batch of rows to the sink. Called for each incoming write batch.
sync
No parameters. Flushes any buffered data to the external sink, ensuring durability. Called at checkpoint boundaries.
drop
No parameters. Releases all resources held by the sink writer. Called when the writer is no longer needed.
Adapter Class Behavior
The Adapter class translates the SinkWriter interface to SinkWriterV1:
| SinkWriter Method | Adapter Behavior |
|---|---|
beginEpoch(long epoch) |
No-op (V1 writers do not track epochs) |
write(Iterable<SinkRow> rows) |
Delegates to inner.write(rows.iterator()); sets hasBegun = true; returns false
|
barrier(boolean isCheckpoint) |
If isCheckpoint and hasBegun, calls inner.sync() and resets hasBegun; always returns Optional.empty()
|
drop() |
Delegates to inner.drop()
|
The hasBegun flag ensures that sync() is only called when rows have actually been written since the last checkpoint, avoiding unnecessary flush operations.
Usage Examples
// Implementing a V1 sink writer
public class MySimpleSinkWriter implements SinkWriterV1 {
@Override
public void write(Iterator<SinkRow> rows) {
while (rows.hasNext()) {
SinkRow row = rows.next();
// Write row to external system
}
}
@Override
public void sync() {
// Flush buffered data to ensure durability
}
@Override
public void drop() {
// Release resources (connections, buffers, etc.)
}
}
// Wrapping a V1 writer with the Adapter for use with the current SinkWriter interface
SinkWriterV1 v1Writer = new MySimpleSinkWriter();
SinkWriter writer = new SinkWriterV1.Adapter(v1Writer);
// The adapter can be used wherever SinkWriter is expected
writer.beginEpoch(1L);
writer.write(rowIterable);
writer.barrier(true); // triggers sync() on the V1 writer
writer.drop();
Related Pages
- SinkRow Interface - The row objects consumed by
write() - Deserializer Interface - Produces the
SinkRowiterables passed to sink writers - TableSchema - Describes the schema of rows being written
- SinkFactory CreateWriter - Factory method that creates sink writer instances
- SinkWriterStreamObserver OnNext - The gRPC stream handler that drives sink writer operations