-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Engine]Support IMap File Storage #3418
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5326a97
[Engine]Support IMap File Storage
CalvinKirs 6213de7
delete test code
CalvinKirs cc08aee
add docs and fix some check style
CalvinKirs 4160db2
add the license files
CalvinKirs 2e39d8d
Add some docs and properties desc
CalvinKirs d08d32e
Fix bug and add UT
CalvinKirs dc1b7e3
revert some local change
CalvinKirs b154ae0
add license header
CalvinKirs 06aea09
add license header
CalvinKirs 32c888e
Merge remote-tracking branch 'upstream/dev' into imap-storage
CalvinKirs 337a9cc
refeact storage
CalvinKirs 072840b
add commons-lang3 dependencys
CalvinKirs 64a6c6b
used common lang3.version and manage dependency in engine module
CalvinKirs b84f049
update licenses
CalvinKirs e3c2391
setting test scope
CalvinKirs 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
45 changes: 45 additions & 0 deletions
45
seatunnel-engine/seatunnel-engine-storage/imap-storage-api/pom.xml
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,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
~ | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>seatunnel-engine-storage</artifactId> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<version>${revision}</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>imap-storage-api</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.protostuff</groupId> | ||
<artifactId>protostuff-core</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.protostuff</groupId> | ||
<artifactId>protostuff-runtime</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
68 changes: 68 additions & 0 deletions
68
...p-storage-api/src/main/java/org/apache/seatunnel/engine/imap/storage/api/IMapStorage.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,68 @@ | ||
/* | ||
* 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.api; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public interface IMapStorage { | ||
|
||
public void initialize(Map<String, Object> properties); | ||
|
||
/** | ||
* Store a key-value pair in the map. | ||
* @param key storage key | ||
* @param value storage value | ||
* @return storage status, true is success, false is fail | ||
*/ | ||
public boolean store(Object key, Object value); | ||
|
||
/** | ||
* Store a key-value pair in the map storage. | ||
* @param map storage key-value pair | ||
* @return if some key-value pair is not stored, return this keys; | ||
* if all key-value pair is stored, return empty set. | ||
*/ | ||
public Set<Object> storeAll(Map<Object, Object> map); | ||
|
||
/** | ||
* Delete a key in the map storage. | ||
* @param key storage key | ||
* @return storage status, true is success, false is fail | ||
*/ | ||
public boolean delete(Object key); | ||
|
||
/** | ||
* Delete a collection of keys from the map storage. | ||
* @param keys delete keys | ||
* @return if some keys delete fail, will return this keys | ||
* if all keys delete success, will return empty set | ||
*/ | ||
public Set<Object> deleteAll(Collection<Object> keys); | ||
|
||
public Map<Object, Object> loadAll() throws IOException; | ||
|
||
public Set<Object> loadAllKeys(); | ||
|
||
public void destroy(); | ||
} |
134 changes: 134 additions & 0 deletions
134
...c/main/java/org/apache/seatunnel/engine/imap/storage/api/common/ProtoStuffSerializer.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,134 @@ | ||
/* | ||
* 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.api.common; | ||
|
||
import io.protostuff.LinkedBuffer; | ||
import io.protostuff.ProtostuffIOUtil; | ||
import io.protostuff.Schema; | ||
import io.protostuff.runtime.RuntimeSchema; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Hashtable; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.SortedMap; | ||
import java.util.TreeMap; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* Todo: move to common module | ||
*/ | ||
@Slf4j | ||
public class ProtoStuffSerializer implements Serializer { | ||
|
||
/** | ||
* At the moment it looks like we only have one Schema. | ||
*/ | ||
private static final Map<Class<?>, Schema<?>> SCHEMA_CACHE = new ConcurrentHashMap<>(); | ||
|
||
@SuppressWarnings("unchecked") | ||
private static <T> Schema<T> getSchema(Class<T> clazz) { | ||
return (Schema<T>) SCHEMA_CACHE.computeIfAbsent(clazz, RuntimeSchema::createFrom); | ||
} | ||
|
||
private static final Set<Class<?>> WRAPPERS = new HashSet<>(); | ||
|
||
private static final Class<SerializerDeserializerWrapper> WRAPPER_CLASS = SerializerDeserializerWrapper.class; | ||
|
||
private static final Schema<SerializerDeserializerWrapper> WRAPPER_SCHEMA = getSchema(WRAPPER_CLASS); | ||
|
||
static { | ||
WRAPPERS.add(Boolean.class); | ||
WRAPPERS.add(Byte.class); | ||
WRAPPERS.add(Character.class); | ||
WRAPPERS.add(Short.class); | ||
WRAPPERS.add(Integer.class); | ||
WRAPPERS.add(Long.class); | ||
WRAPPERS.add(Float.class); | ||
WRAPPERS.add(Double.class); | ||
WRAPPERS.add(String.class); | ||
WRAPPERS.add(Void.class); | ||
WRAPPERS.add(List.class); | ||
WRAPPERS.add(ArrayList.class); | ||
WRAPPERS.add(Map.class); | ||
WRAPPERS.add(HashMap.class); | ||
WRAPPERS.add(TreeMap.class); | ||
WRAPPERS.add(Hashtable.class); | ||
WRAPPERS.add(SortedMap.class); | ||
} | ||
|
||
@Override | ||
public <T> byte[] serialize(T obj) { | ||
Class<T> clazz = (Class<T>) obj.getClass(); | ||
LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE); | ||
Schema schema = WRAPPER_SCHEMA; | ||
if (WRAPPERS.contains(clazz)) { | ||
obj = (T) SerializerDeserializerWrapper.of(obj); | ||
} else { | ||
schema = getSchema(clazz); | ||
} | ||
|
||
byte[] data; | ||
try { | ||
data = ProtostuffIOUtil.toByteArray(obj, schema, buffer); | ||
} finally { | ||
buffer.clear(); | ||
} | ||
return data; | ||
} | ||
|
||
@Override | ||
public <T> T deserialize(byte[] data, Class<T> clz) { | ||
|
||
if (!WRAPPERS.contains(clz)) { | ||
Schema<T> schema = getSchema(clz); | ||
T message = schema.newMessage(); | ||
ProtostuffIOUtil.mergeFrom(data, message, schema); | ||
return message; | ||
} | ||
SerializerDeserializerWrapper<T> wrapper = new SerializerDeserializerWrapper<>(); | ||
ProtostuffIOUtil.mergeFrom(data, wrapper, WRAPPER_SCHEMA); | ||
return wrapper.getObj(); | ||
} | ||
|
||
public static class SerializerDeserializerWrapper<T> { | ||
private T obj; | ||
|
||
public static <T> SerializerDeserializerWrapper<T> of(T obj) { | ||
SerializerDeserializerWrapper<T> wrapper = new SerializerDeserializerWrapper<>(); | ||
wrapper.setObj(obj); | ||
return wrapper; | ||
} | ||
|
||
public T getObj() { | ||
return obj; | ||
} | ||
|
||
public void setObj(T obj) { | ||
this.obj = obj; | ||
} | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...age-api/src/main/java/org/apache/seatunnel/engine/imap/storage/api/common/Serializer.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,33 @@ | ||
/* | ||
* 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.api.common; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Todo: move to common module | ||
*/ | ||
public interface Serializer { | ||
|
||
<T> byte[] serialize(T obj) throws IOException; | ||
|
||
<T> T deserialize(byte[] data, Class<T> clz) throws IOException; | ||
} |
40 changes: 40 additions & 0 deletions
40
...ain/java/org/apache/seatunnel/engine/imap/storage/api/exception/IMapStorageException.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,40 @@ | ||
/* | ||
* 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.api.exception; | ||
|
||
public class IMapStorageException extends RuntimeException { | ||
|
||
public IMapStorageException(String message) { | ||
super(message); | ||
} | ||
|
||
public IMapStorageException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public IMapStorageException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public IMapStorageException(Throwable cause, String message, Object... data) { | ||
super(String.format(message, data), cause); | ||
} | ||
} |
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.
Other APIs support Object type key?
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.
For File Storage, we do not have a key of type Object, and all keys need to be defined internally by File