You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tz...@apache.org on 2021/03/10 06:44:23 UTC
[flink-statefun] branch master updated (76858f5 -> b1c50db)
This is an automated email from the ASF dual-hosted git repository.
tzulitai pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/flink-statefun.git.
from 76858f5 [FLINK-21577] [java] Fix instantiation error with SimpleType.simpleTypeFrom()
add 65e6f1b [hotfix] Rename ValueSpec.withUtf8String(...)
add c85f293 [FLINK-21662] Restrict registering multiple ValueSpecs under same state name
add 3845226 [FLINK-21663] Restrict registering mulitple StatefulFunctionSpec under the same function typename
add 7244efc [hotfix] Incorrect arg null check in KafkaEgressMessage.withValue(Slice)
add 9ea565e [hotfix] Add a withTopic(Slice) method to KafkaEgressMessage
add 5e6e05b [FLINK-21676] Ensure that state names are valid identifiers in Java SDK
add 039b2d2 [FLINK-21678] Rename expiresAfterReadOrWrite to expiresAfterCall in Java SDK
new b1c50db [FLINK-21705] Add a SliceType
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/flink/statefun/sdk/java/Expiration.java | 11 ++--
.../statefun/sdk/java/StatefulFunctionSpec.java | 14 ++++-
.../flink/statefun/sdk/java/StatefulFunctions.java | 10 ++--
.../apache/flink/statefun/sdk/java/ValueSpec.java | 58 ++++++++++++++++++--
.../statefun/sdk/java/handler/ProtoUtils.java | 2 +-
.../statefun/sdk/java/io/KafkaEgressMessage.java | 7 ++-
.../SliceType.java} | 49 ++++++++++-------
.../src/test/java/ValueSpecTest.java | 37 +++++++------
.../sdk/java/StatefulFunctionSpecTest.java | 62 ++++++++++++++++++++++
.../handler/ConcurrentRequestReplyHandlerTest.java | 2 +-
.../ConcurrentAddressScopedStorageTest.java | 10 ++--
.../sdk/java/storage/StateValueContextsTest.java | 34 ++++++------
.../sdk/java/types/SanityPrimitiveTypeTest.java | 9 ++++
13 files changed, 228 insertions(+), 77 deletions(-)
copy statefun-sdk-java/src/main/java/org/apache/flink/statefun/sdk/java/{message/EgressMessageWrapper.java => types/SliceType.java} (50%)
copy statefun-flink/statefun-flink-core/src/test/java/org/apache/flink/statefun/flink/core/cache/SingleThreadedLruCacheTest.java => statefun-sdk-java/src/test/java/ValueSpecTest.java (53%)
create mode 100644 statefun-sdk-java/src/test/java/org/apache/flink/statefun/sdk/java/StatefulFunctionSpecTest.java
[flink-statefun] 01/01: [FLINK-21705] Add a SliceType
Posted by tz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tzulitai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink-statefun.git
commit b1c50db25b9610e0362ab56dbd718b39d63cee2d
Author: Tzu-Li (Gordon) Tai <tz...@apache.org>
AuthorDate: Wed Mar 10 14:35:34 2021 +0800
[FLINK-21705] Add a SliceType
A SliceType is a type that simply treats the value as raw bytes. The
serializer implementation simply forwards the bytes as is, without any
copying. Since slices are immutable, the type is considered immutable.
This type can come in handy if users would like to avoid serialization /
deserialization in certain scenarios, e.g. sending state values as a
message to another function.
This closes #209.
---
.../flink/statefun/sdk/java/types/SliceType.java | 66 ++++++++++++++++++++++
.../sdk/java/types/SanityPrimitiveTypeTest.java | 9 +++
2 files changed, 75 insertions(+)
diff --git a/statefun-sdk-java/src/main/java/org/apache/flink/statefun/sdk/java/types/SliceType.java b/statefun-sdk-java/src/main/java/org/apache/flink/statefun/sdk/java/types/SliceType.java
new file mode 100644
index 0000000..1a95462
--- /dev/null
+++ b/statefun-sdk-java/src/main/java/org/apache/flink/statefun/sdk/java/types/SliceType.java
@@ -0,0 +1,66 @@
+/*
+ * 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.flink.statefun.sdk.java.types;
+
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Objects;
+import java.util.Set;
+import org.apache.flink.statefun.sdk.java.TypeName;
+import org.apache.flink.statefun.sdk.java.slice.Slice;
+
+public final class SliceType implements Type<Slice> {
+
+ private static final Set<TypeCharacteristics> IMMUTABLE_TYPE_CHARS =
+ Collections.unmodifiableSet(EnumSet.of(TypeCharacteristics.IMMUTABLE_VALUES));
+
+ private final TypeName typename;
+ private final Serializer serializer = new Serializer();
+
+ public SliceType(TypeName typename) {
+ this.typename = Objects.requireNonNull(typename);
+ }
+
+ @Override
+ public TypeName typeName() {
+ return typename;
+ }
+
+ @Override
+ public TypeSerializer<Slice> typeSerializer() {
+ return serializer;
+ }
+
+ @Override
+ public Set<TypeCharacteristics> typeCharacteristics() {
+ return IMMUTABLE_TYPE_CHARS;
+ }
+
+ private static final class Serializer implements TypeSerializer<Slice> {
+ @Override
+ public Slice serialize(Slice slice) {
+ return slice;
+ }
+
+ @Override
+ public Slice deserialize(Slice slice) {
+ return slice;
+ }
+ }
+}
diff --git a/statefun-sdk-java/src/test/java/org/apache/flink/statefun/sdk/java/types/SanityPrimitiveTypeTest.java b/statefun-sdk-java/src/test/java/org/apache/flink/statefun/sdk/java/types/SanityPrimitiveTypeTest.java
index 73650e8..01e7884 100644
--- a/statefun-sdk-java/src/test/java/org/apache/flink/statefun/sdk/java/types/SanityPrimitiveTypeTest.java
+++ b/statefun-sdk-java/src/test/java/org/apache/flink/statefun/sdk/java/types/SanityPrimitiveTypeTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ThreadLocalRandom;
+import org.apache.flink.statefun.sdk.java.TypeName;
import org.apache.flink.statefun.sdk.java.slice.Slice;
import org.apache.flink.statefun.sdk.java.slice.Slices;
import org.apache.flink.statefun.sdk.shaded.com.google.protobuf.InvalidProtocolBufferException;
@@ -80,6 +81,14 @@ public class SanityPrimitiveTypeTest {
}
@Test
+ public void testSlice() {
+ final TypeName typename = TypeName.typeNameOf("test.namespace", "test.name");
+ assertRoundTrip(
+ new SliceType(typename), Slices.wrap("payload-foobar".getBytes(StandardCharsets.UTF_8)));
+ assertRoundTrip(new SliceType(typename), Slices.wrap(new byte[] {}));
+ }
+
+ @Test
public void testRandomCompatibilityWithAnIntegerWrapper() throws InvalidProtocolBufferException {
TypeSerializer<Integer> serializer = Types.integerType().typeSerializer();
for (int i = 0; i < 1_000_000; i++) {