-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature][SeaTunnel Engine IMap Storage] Add OSS support for Imap storage to cluster-mode type #4683
Merged
+1,412
−129
Merged
[Feature][SeaTunnel Engine IMap Storage] Add OSS support for Imap storage to cluster-mode type #4683
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
838db3d
Add OSS/S3 to cluster-mode type #4621
sunxiaojian cac6ab4
fixed bug & add e2e test
sunxiaojian 62a3189
Wait for the node to start before scheduling & Move jar to parent po…
sunxiaojian 2e9ba5e
Merge branch 'dev' into support-oss
sunxiaojian 5b806ee
update LICENSE
sunxiaojian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
123 changes: 123 additions & 0 deletions
123
...e/src/main/java/org/apache/seatunnel/engine/imap/storage/file/wal/writer/CloudWriter.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,123 @@ | ||
/* | ||
* 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.seatunnel.engine.imap.storage.file.wal.writer; | ||
|
||
import org.apache.seatunnel.engine.imap.storage.api.exception.IMapStorageException; | ||
import org.apache.seatunnel.engine.imap.storage.file.bean.IMapFileData; | ||
import org.apache.seatunnel.engine.imap.storage.file.common.WALDataUtils; | ||
import org.apache.seatunnel.engine.serializer.api.Serializer; | ||
|
||
import org.apache.curator.shaded.com.google.common.io.ByteStreams; | ||
import org.apache.hadoop.fs.FSDataInputStream; | ||
import org.apache.hadoop.fs.FSDataOutputStream; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
@Slf4j | ||
public abstract class CloudWriter implements IFileWriter<IMapFileData> { | ||
private FileSystem fs; | ||
private Path parentPath; | ||
private Path path; | ||
private Serializer serializer; | ||
|
||
private ByteBuf bf = Unpooled.buffer(1024); | ||
|
||
// block size, default 1024*1024 | ||
private long blockSize = 1024 * 1024; | ||
|
||
private AtomicLong index = new AtomicLong(0); | ||
|
||
@Override | ||
public void initialize(FileSystem fs, Path parentPath, Serializer serializer) | ||
throws IOException { | ||
|
||
this.fs = fs; | ||
this.serializer = serializer; | ||
this.parentPath = parentPath; | ||
this.path = createNewPath(); | ||
if (fs.exists(path)) { | ||
try (FSDataInputStream fsDataInputStream = fs.open(path)) { | ||
bf.writeBytes(ByteStreams.toByteArray(fsDataInputStream)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void setBlockSize(Long blockSize) { | ||
if (blockSize != null && blockSize > DEFAULT_BLOCK_SIZE) { | ||
this.blockSize = blockSize; | ||
} | ||
} | ||
|
||
// TODO Synchronous write, asynchronous write can be added in the future | ||
@Override | ||
public void write(IMapFileData data) throws IOException { | ||
byte[] bytes = serializer.serialize(data); | ||
this.write(bytes); | ||
} | ||
|
||
private void write(byte[] bytes) { | ||
try (FSDataOutputStream out = fs.create(path, true)) { | ||
// Write to bytebuffer | ||
byte[] data = WALDataUtils.wrapperBytes(bytes); | ||
bf.writeBytes(data); | ||
|
||
// Read all bytes | ||
byte[] allBytes = new byte[bf.readableBytes()]; | ||
bf.readBytes(allBytes); | ||
|
||
// write filesystem | ||
out.write(allBytes); | ||
|
||
// check and reset | ||
checkAndSetNextScheduleRotation(allBytes.length); | ||
|
||
} catch (Exception ex) { | ||
throw new IMapStorageException(ex); | ||
} | ||
} | ||
|
||
private void checkAndSetNextScheduleRotation(long allBytes) { | ||
if (allBytes > blockSize) { | ||
this.path = createNewPath(); | ||
this.bf.clear(); | ||
} else { | ||
// reset index | ||
bf.resetReaderIndex(); | ||
} | ||
} | ||
|
||
public Path createNewPath() { | ||
return new Path(parentPath, index.incrementAndGet() + "_" + FILE_NAME); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
bf.clear(); | ||
this.bf = null; | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EricJoy2048 @Hisoka-X please check