-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Adapt to sink v2 api FLIP-191
Signed-off-by: PengFei Li <[email protected]>
- Loading branch information
Showing
13 changed files
with
668 additions
and
29 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
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
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
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
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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/starrocks/connector/flink/table/sink/v2/StarRocksCommittable.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,36 @@ | ||
/* | ||
* Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
* | ||
* 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 com.starrocks.connector.flink.table.sink.v2; | ||
|
||
import com.starrocks.data.load.stream.StreamLoadSnapshot; | ||
|
||
public class StarRocksCommittable { | ||
|
||
private final StreamLoadSnapshot labelSnapshot; | ||
|
||
public StarRocksCommittable(StreamLoadSnapshot labelSnapshot) { | ||
this.labelSnapshot = labelSnapshot; | ||
} | ||
|
||
public StreamLoadSnapshot getLabelSnapshot() { | ||
return labelSnapshot; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...main/java/com/starrocks/connector/flink/table/sink/v2/StarRocksCommittableSerializer.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,50 @@ | ||
/* | ||
* Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
* | ||
* 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 com.starrocks.connector.flink.table.sink.v2; | ||
|
||
import com.starrocks.connector.flink.tools.JsonWrapper; | ||
import org.apache.flink.core.io.SimpleVersionedSerializer; | ||
|
||
import java.io.IOException; | ||
|
||
public class StarRocksCommittableSerializer implements SimpleVersionedSerializer<StarRocksCommittable> { | ||
|
||
private final JsonWrapper jsonWrapper; | ||
|
||
public StarRocksCommittableSerializer() { | ||
this.jsonWrapper = new JsonWrapper(); | ||
} | ||
|
||
@Override | ||
public int getVersion() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
public byte[] serialize(StarRocksCommittable committable) throws IOException { | ||
return jsonWrapper.toJSONBytes(committable); | ||
} | ||
|
||
@Override | ||
public StarRocksCommittable deserialize(int version, byte[] serialized) throws IOException { | ||
return jsonWrapper.parseObject(serialized, StarRocksCommittable.class); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/com/starrocks/connector/flink/table/sink/v2/StarRocksCommitter.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,77 @@ | ||
/* | ||
* Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
* | ||
* 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 com.starrocks.connector.flink.table.sink.v2; | ||
|
||
import com.starrocks.connector.flink.table.sink.StarRocksSinkOptions; | ||
import com.starrocks.connector.flink.table.sink.StarRocksSinkSemantic; | ||
import com.starrocks.data.load.stream.properties.StreamLoadProperties; | ||
import com.starrocks.data.load.stream.v2.StreamLoadManagerV2; | ||
import org.apache.flink.api.connector.sink2.Committer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
|
||
public class StarRocksCommitter implements Committer<StarRocksCommittable> { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(StarRocksCommitter.class); | ||
|
||
private final StreamLoadManagerV2 sinkManager; | ||
|
||
public StarRocksCommitter( | ||
StarRocksSinkOptions sinkOptions, | ||
StreamLoadProperties streamLoadProperties) { | ||
this.sinkManager = new StreamLoadManagerV2(streamLoadProperties, | ||
sinkOptions.getSemantic() == StarRocksSinkSemantic.AT_LEAST_ONCE); | ||
try { | ||
// TODO no need to start flush thread in sinkManager | ||
sinkManager.init(); | ||
} catch (Exception e) { | ||
LOG.error("Failed to init sink manager.", e); | ||
try { | ||
sinkManager.close(); | ||
} catch (Exception ie) { | ||
LOG.error("Failed to close sink manager after init failure.", ie); | ||
} | ||
throw new RuntimeException("Failed to init sink manager", e); | ||
} | ||
LOG.info("Create StarRocksCommitter."); | ||
} | ||
|
||
@Override | ||
public void commit(Collection<CommitRequest<StarRocksCommittable>> committables) | ||
throws IOException, InterruptedException { | ||
// TODO deal with retyr and fatal errors | ||
for (CommitRequest<StarRocksCommittable> commitRequest : committables) { | ||
StarRocksCommittable committable = commitRequest.getCommittable(); | ||
sinkManager.commit(committable.getLabelSnapshot()); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
LOG.info("Close StarRocksCommitter."); | ||
if(sinkManager != null) { | ||
sinkManager.close(); | ||
} | ||
} | ||
} |
Oops, something went wrong.