org.apache.kudu.client.SessionConfiguration.FlushMode Java Examples

The following examples show how to use org.apache.kudu.client.SessionConfiguration.FlushMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KuduUpdatablePageSource.java    From presto-kudu with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteRows(Block rowIds) {
    Schema schema = table.getSchema();
    KuduSession session = clientSession.newSession();
    session.setFlushMode(FlushMode.AUTO_FLUSH_BACKGROUND);
    try {
        try {
            for (int i = 0; i < rowIds.getPositionCount(); i++) {
                int len = rowIds.getSliceLength(i);
                Slice slice = rowIds.getSlice(i, 0, len);
                PartialRow row = KeyEncoderAccessor.decodePrimaryKey(schema, slice.getBytes());
                Delete delete = table.newDelete();
                RowHelper.copyPrimaryKey(schema, row, delete.getRow());
                session.apply(delete);
            }
        } finally {
            session.close();
        }
    } catch (KuduException e) {
        throw new RuntimeException(e);
    }
}
 
Example #2
Source File: KuduUpdatablePageSource.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteRows(Block rowIds)
{
    Schema schema = table.getSchema();
    KuduSession session = clientSession.newSession();
    session.setFlushMode(FlushMode.AUTO_FLUSH_BACKGROUND);
    try {
        try {
            for (int i = 0; i < rowIds.getPositionCount(); i++) {
                int len = rowIds.getSliceLength(i);
                Slice slice = rowIds.getSlice(i, 0, len);
                PartialRow row = KeyEncoderAccessor.decodePrimaryKey(schema, slice.getBytes());
                Delete delete = table.newDelete();
                RowHelper.copyPrimaryKey(schema, row, delete.getRow());
                session.apply(delete);
            }
        }
        finally {
            session.close();
        }
    }
    catch (KuduException e) {
        throw new RuntimeException(e);
    }
}
 
Example #3
Source File: KuduSink.java    From flink-learning with Apache License 2.0 5 votes vote down vote up
/**
 * If flink checkpoint is disable,synchronously write data to kudu.
 * <p>If flink checkpoint is enable, asynchronously write data to kudu by default.
 *
 * <p>(Note: async may result in out-of-order writes to Kudu.
 *  you also can change to sync by explicitly calling {@link KuduSink#withSyncFlushMode()} when initializing KuduSink. )
 *
 * @return flushMode
 */
private FlushMode getflushMode() {
    FlushMode flushMode = FlushMode.AUTO_FLUSH_SYNC;
    boolean enableCheckpoint = ((StreamingRuntimeContext) getRuntimeContext()).isCheckpointingEnabled();
    if(enableCheckpoint && this.flushMode == null) {
        flushMode = FlushMode.AUTO_FLUSH_BACKGROUND;
    }
    if(enableCheckpoint && this.flushMode != null) {
        flushMode = this.flushMode;
    }
    return flushMode;
}
 
Example #4
Source File: KuduConnector.java    From flink-learning with Apache License 2.0 5 votes vote down vote up
public KuduConnector(String kuduMasters, KuduTableInfo tableInfo, Consistency consistency, WriteMode writeMode, FlushMode flushMode) throws IOException {
    this.client = client(kuduMasters);
    this.table = table(tableInfo);
    this.session = client.newSession();
    this.consistency = consistency;
    this.writeMode = writeMode;
    this.defaultCB = new ResponseCallback();
    this.session.setFlushMode(flushMode);
}
 
Example #5
Source File: KuduConnector.java    From flink-learning with Apache License 2.0 5 votes vote down vote up
public KuduConnector(String kuduMasters, KuduTableInfo tableInfo, Consistency consistency, WriteMode writeMode, FlushMode flushMode) throws IOException {
    this.client = client(kuduMasters);
    this.table = table(tableInfo);
    this.session = client.newSession();
    this.consistency = consistency;
    this.writeMode = writeMode;
    this.defaultCB = new ResponseCallback();
    this.session.setFlushMode(flushMode);
}
 
Example #6
Source File: KuduSink.java    From flink-learning with Apache License 2.0 5 votes vote down vote up
/**
 * If flink checkpoint is disable,synchronously write data to kudu.
 * <p>If flink checkpoint is enable, asynchronously write data to kudu by default.
 *
 * <p>(Note: async may result in out-of-order writes to Kudu.
 *  you also can change to sync by explicitly calling {@link KuduSink#withSyncFlushMode()} when initializing KuduSink. )
 *
 * @return flushMode
 */
private FlushMode getflushMode() {
    FlushMode flushMode = FlushMode.AUTO_FLUSH_SYNC;
    boolean enableCheckpoint = ((StreamingRuntimeContext) getRuntimeContext()).isCheckpointingEnabled();
    if(enableCheckpoint && this.flushMode == null) {
        flushMode = FlushMode.AUTO_FLUSH_BACKGROUND;
    }
    if(enableCheckpoint && this.flushMode != null) {
        flushMode = this.flushMode;
    }
    return flushMode;
}
 
Example #7
Source File: KuduSink.java    From flink-learning with Apache License 2.0 4 votes vote down vote up
public KuduSink<OUT> withAsyncFlushMode() {
    this.flushMode = FlushMode.AUTO_FLUSH_BACKGROUND;
    return this;
}
 
Example #8
Source File: TestPutKudu.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testKuduPartialFailuresOnManualFlush() throws Exception {
    testKuduPartialFailure(FlushMode.MANUAL_FLUSH);
}
 
Example #9
Source File: TestPutKudu.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testKuduPartialFailuresOnAutoFlushBackground() throws Exception {
    testKuduPartialFailure(FlushMode.AUTO_FLUSH_BACKGROUND);
}
 
Example #10
Source File: TestPutKudu.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testKuduPartialFailuresOnAutoFlushSync() throws Exception {
    testKuduPartialFailure(FlushMode.AUTO_FLUSH_SYNC);
}
 
Example #11
Source File: TestPutKudu.java    From nifi with Apache License 2.0 4 votes vote down vote up
private void testKuduPartialFailure(FlushMode flushMode) throws Exception {
  // Test against different batch sizes (up until the point where every record can be buffered at once)
  for (int i = 1; i <= 11; i++) {
      testKuduPartialFailure(flushMode, i);
  }
}
 
Example #12
Source File: KuduConnector.java    From flink-learning with Apache License 2.0 4 votes vote down vote up
public KuduConnector(String kuduMasters, KuduTableInfo tableInfo) throws IOException {
    this(kuduMasters, tableInfo, KuduConnector.Consistency.STRONG, KuduConnector.WriteMode.UPSERT, FlushMode.AUTO_FLUSH_SYNC);
}
 
Example #13
Source File: KuduSink.java    From flink-learning with Apache License 2.0 4 votes vote down vote up
public KuduSink<OUT> withSyncFlushMode() {
    this.flushMode = FlushMode.AUTO_FLUSH_SYNC;
    return this;
}
 
Example #14
Source File: KuduOutputFormat.java    From flink-learning with Apache License 2.0 4 votes vote down vote up
@Override
public void open(int taskNumber, int numTasks) throws IOException {
    if (connector != null) return;
    connector = new KuduConnector(kuduMasters, tableInfo, consistency, writeMode,FlushMode.AUTO_FLUSH_SYNC);
    serializer = serializer.withSchema(tableInfo.getSchema());
}
 
Example #15
Source File: KuduConnector.java    From flink-learning with Apache License 2.0 4 votes vote down vote up
public KuduConnector(String kuduMasters, KuduTableInfo tableInfo) throws IOException {
    this(kuduMasters, tableInfo, KuduConnector.Consistency.STRONG, KuduConnector.WriteMode.UPSERT, FlushMode.AUTO_FLUSH_SYNC);
}
 
Example #16
Source File: KuduSink.java    From flink-learning with Apache License 2.0 4 votes vote down vote up
public KuduSink<OUT> withAsyncFlushMode() {
    this.flushMode = FlushMode.AUTO_FLUSH_BACKGROUND;
    return this;
}
 
Example #17
Source File: KuduSink.java    From flink-learning with Apache License 2.0 4 votes vote down vote up
public KuduSink<OUT> withSyncFlushMode() {
    this.flushMode = FlushMode.AUTO_FLUSH_SYNC;
    return this;
}
 
Example #18
Source File: KuduOutputFormat.java    From flink-learning with Apache License 2.0 4 votes vote down vote up
@Override
public void open(int taskNumber, int numTasks) throws IOException {
    if (connector != null) return;
    connector = new KuduConnector(kuduMasters, tableInfo, consistency, writeMode,FlushMode.AUTO_FLUSH_SYNC);
    serializer = serializer.withSchema(tableInfo.getSchema());
}