Skip to content

Commit

Permalink
[HUDI-4907] Prevent single commit multi instant issue (#6766)
Browse files Browse the repository at this point in the history
Co-authored-by: TengHuo <teng_huo@outlook.com>
Co-authored-by: yuzhao.cyz <yuzhao.cyz@gmail.com>
  • Loading branch information
3 people committed Sep 27, 2022
1 parent db03e1f commit 28e3db1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Expand Up @@ -341,7 +341,7 @@ private static void initMetadataTable(HoodieFlinkWriteClient<?> writeClient) {

private static CkpMetadata initCkpMetadata(HoodieTableMetaClient metaClient) throws IOException {
CkpMetadata ckpMetadata = CkpMetadata.getInstance(metaClient.getFs(), metaClient.getBasePath());
ckpMetadata.bootstrap(metaClient);
ckpMetadata.bootstrap();
return ckpMetadata;
}

Expand Down
Expand Up @@ -94,7 +94,7 @@ public void close() {
*
* <p>This expects to be called by the driver.
*/
public void bootstrap(HoodieTableMetaClient metaClient) throws IOException {
public void bootstrap() throws IOException {
fs.delete(path, true);
fs.mkdirs(path);
}
Expand Down Expand Up @@ -173,8 +173,8 @@ private void load() {
@Nullable
public String lastPendingInstant() {
load();
for (int i = this.messages.size() - 1; i >= 0; i--) {
CkpMessage ckpMsg = this.messages.get(i);
if (this.messages.size() > 0) {
CkpMessage ckpMsg = this.messages.get(this.messages.size() - 1);
// consider 'aborted' as pending too to reuse the instant
if (!ckpMsg.isComplete()) {
return ckpMsg.getInstant();
Expand Down
Expand Up @@ -32,6 +32,7 @@
import java.io.File;
import java.util.stream.IntStream;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

Expand Down Expand Up @@ -63,7 +64,7 @@ void testWriteAndReadMessage() {

assertThat(metadata.lastPendingInstant(), is("2"));
metadata.commitInstant("2");
assertThat(metadata.lastPendingInstant(), is("1"));
assertThat(metadata.lastPendingInstant(), equalTo(null));

// test cleaning
IntStream.range(3, 6).forEach(i -> metadata.startInstant(i + ""));
Expand Down

0 comments on commit 28e3db1

Please sign in to comment.