forked from apache/doris-flink-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Improve] Fix the problem caused by very small interval in batch mode (…
- Loading branch information
Showing
16 changed files
with
793 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...oris-connector/src/main/java/org/apache/doris/flink/sink/batch/BatchBufferHttpEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.doris.flink.sink.batch; | ||
|
||
import org.apache.http.entity.AbstractHttpEntity; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.List; | ||
|
||
public class BatchBufferHttpEntity extends AbstractHttpEntity { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(BatchBufferHttpEntity.class); | ||
protected static final int OUTPUT_BUFFER_SIZE = 4096; | ||
private final List<byte[]> buffer; | ||
private final long contentLength; | ||
|
||
public BatchBufferHttpEntity(BatchRecordBuffer recordBuffer) { | ||
this.buffer = recordBuffer.getBuffer(); | ||
this.contentLength = recordBuffer.getBufferSizeBytes(); | ||
} | ||
|
||
@Override | ||
public boolean isRepeatable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isChunked() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public long getContentLength() { | ||
return contentLength; | ||
} | ||
|
||
@Override | ||
public InputStream getContent() { | ||
return new BatchBufferStream(buffer); | ||
} | ||
|
||
@Override | ||
public void writeTo(OutputStream outStream) throws IOException { | ||
try (InputStream inStream = new BatchBufferStream(buffer)) { | ||
final byte[] buffer = new byte[OUTPUT_BUFFER_SIZE]; | ||
int readLen; | ||
while ((readLen = inStream.read(buffer)) != -1) { | ||
outStream.write(buffer, 0, readLen); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isStreaming() { | ||
return false; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
flink-doris-connector/src/main/java/org/apache/doris/flink/sink/batch/BatchBufferStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.doris.flink.sink.batch; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
public class BatchBufferStream extends InputStream { | ||
private final Iterator<byte[]> iterator; | ||
private byte[] currentRow; | ||
private int currentPos; | ||
|
||
public BatchBufferStream(List<byte[]> buffer) { | ||
this.iterator = buffer.iterator(); | ||
} | ||
|
||
@Override | ||
public int read() throws IOException { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int read(byte[] buf) throws IOException { | ||
return read(buf, 0, buf.length); | ||
} | ||
|
||
@Override | ||
public int read(byte[] buf, int off, int len) throws IOException { | ||
if (!iterator.hasNext() && currentRow == null) { | ||
return -1; | ||
} | ||
|
||
byte[] item = currentRow; | ||
int pos = currentPos; | ||
int readBytes = 0; | ||
while (readBytes < len && (item != null || iterator.hasNext())) { | ||
if (item == null) { | ||
item = iterator.next(); | ||
pos = 0; | ||
} | ||
|
||
int size = Math.min(len - readBytes, item.length - pos); | ||
System.arraycopy(item, pos, buf, off + readBytes, size); | ||
readBytes += size; | ||
pos += size; | ||
|
||
if (pos == item.length) { | ||
item = null; | ||
pos = 0; | ||
} | ||
} | ||
currentRow = item; | ||
currentPos = pos; | ||
return readBytes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.