Skip to content

Commit c45d18e

Browse files
committed
[Fix #1691] Add metadata to mvstore
Signed-off-by: Francisco Javier Tirado Sarti <ftirados@ibm.com>
1 parent 8894b06 commit c45d18e

20 files changed

Lines changed: 529 additions & 35 deletions

File tree

‎impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowMutableInstance.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class WorkflowMutableInstance implements WorkflowInstance {
5353
protected AtomicReference<CompletableFuture<WorkflowModel>> futureRef = new AtomicReference<>();
5454
protected Instant completedAt;
5555

56-
protected final Map<String, Object> additionalObjects = new ConcurrentHashMap<>();
56+
protected Map<String, Object> additionalObjects = new ConcurrentHashMap<>();
5757

5858
protected final Map<String, Integer> iterationsMap = new ConcurrentHashMap<>();
5959

@@ -448,6 +448,10 @@ public void addCancelable(CompletableFuture<?> cancelable) {
448448
}
449449
}
450450

451+
protected void setMetadata(Map<String, Object> metadata) {
452+
this.additionalObjects = metadata;
453+
}
454+
451455
@Override
452456
public <T> T addMetadataIfAbsent(String key, Supplier<T> supplier) {
453457
return (T) additionalObjects.computeIfAbsent(key, k -> supplier.get());

‎impl/core/src/main/java/io/serverlessworkflow/impl/marshaller/DefaultOutputBuffer.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ public WorkflowOutputBuffer writeBytes(byte[] bytes) {
122122
return this;
123123
}
124124

125+
@Override
126+
public WorkflowOutputBuffer writeRawBytes(byte[] bytes) {
127+
try {
128+
output.write(bytes);
129+
} catch (IOException e) {
130+
throw new UncheckedIOException(e);
131+
}
132+
return this;
133+
}
134+
125135
@Override
126136
public void close() {
127137
try {

‎impl/core/src/main/java/io/serverlessworkflow/impl/marshaller/MarshallingUtils.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ public static WorkflowModel readModel(WorkflowBufferFactory factory, byte[] valu
173173
return readValue(factory, value, b -> (WorkflowModel) b.readObject());
174174
}
175175

176+
public static Object readObject(WorkflowBufferFactory factory, byte[] value) {
177+
return readValue(factory, value, b -> b.readObject());
178+
}
179+
176180
public static Instant readInstant(WorkflowBufferFactory factory, byte[] value) {
177181
return readValue(factory, value, WorkflowInputBuffer::readInstant);
178182
}

‎impl/core/src/main/java/io/serverlessworkflow/impl/marshaller/WorkflowOutputBuffer.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public interface WorkflowOutputBuffer extends AutoCloseable {
4141

4242
WorkflowOutputBuffer writeBytes(byte[] bytes);
4343

44+
WorkflowOutputBuffer writeRawBytes(byte[] bytes);
45+
4446
WorkflowOutputBuffer writeInstant(Instant instant);
4547

4648
default WorkflowOutputBuffer writeOffsetDateTime(OffsetDateTime time) {

‎impl/persistence/api/src/main/java/io/serverlessworkflow/impl/persistence/CompletedTaskInfo.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717

1818
import io.serverlessworkflow.impl.WorkflowModel;
1919
import java.time.Instant;
20+
import java.util.Map;
2021

2122
public record CompletedTaskInfo(
2223
Instant instant,
2324
WorkflowModel model,
2425
WorkflowModel context,
2526
Boolean isEndNode,
2627
String nextPosition,
27-
int iteration)
28+
int iteration,
29+
Map<String, Object> additionalObjects)
2830
implements PersistenceTaskInfo {
2931

3032
public CompletedTaskInfo(
@@ -35,4 +37,14 @@ public CompletedTaskInfo(
3537
String nextPosition) {
3638
this(instant, model, context, isEndNode, nextPosition, 1);
3739
}
40+
41+
public CompletedTaskInfo(
42+
Instant instant,
43+
WorkflowModel model,
44+
WorkflowModel context,
45+
Boolean isEndNode,
46+
String nextPosition,
47+
int iteration) {
48+
this(instant, model, context, isEndNode, nextPosition, iteration, Map.of());
49+
}
3850
}

‎impl/persistence/api/src/main/java/io/serverlessworkflow/impl/persistence/WorkflowPersistenceInstance.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public void restoreContext(WorkflowContext workflow, TaskContext context) {
8383
: workflow.definition().taskExecutor(completedTaskInfo.nextPosition()),
8484
completedTaskInfo.isEndNode()));
8585
workflow.context(completedTaskInfo.context());
86+
setMetadata(completedTaskInfo.additionalObjects());
8687
} else if (taskInfo instanceof RetriedTaskInfo retriedTaskInfo) {
8788
if (context.retryAttempt() == 0) {
8889
context.retryAttempt(retriedTaskInfo.retryAttempt());
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.persistence.hashing;
17+
18+
import io.serverlessworkflow.impl.marshaller.WorkflowInputBuffer;
19+
import java.util.Optional;
20+
21+
public abstract class AbstractHashFactory implements HashFactory {
22+
23+
@Override
24+
public Optional<HashItem> fromBuffer(byte id, WorkflowInputBuffer buffer) {
25+
return Optional.ofNullable(
26+
switch (id) {
27+
case MD5HashItem.ID -> new MD5HashItem(buffer);
28+
case IntegerHashItem.ID -> new IntegerHashItem(buffer);
29+
default -> null;
30+
});
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.persistence.hashing;
17+
18+
import java.util.Optional;
19+
20+
public class DisabledHashFactory extends AbstractHashFactory {
21+
22+
private static final HashFactory instance = new DisabledHashFactory();
23+
24+
public static HashFactory instance() {
25+
return instance;
26+
}
27+
28+
@Override
29+
public Optional<HashItem> fromData(byte[] data) {
30+
return Optional.empty();
31+
}
32+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.persistence.hashing;
17+
18+
import io.serverlessworkflow.impl.marshaller.WorkflowInputBuffer;
19+
import java.util.Optional;
20+
21+
public interface HashFactory {
22+
23+
Optional<HashItem> fromData(byte[] data);
24+
25+
Optional<HashItem> fromBuffer(byte id, WorkflowInputBuffer buffer);
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.persistence.hashing;
17+
18+
import io.serverlessworkflow.impl.marshaller.WorkflowOutputBuffer;
19+
20+
public interface HashItem {
21+
22+
final byte HASHING_DISABLED = 0;
23+
24+
/**
25+
* byte identifying this hash item type
26+
*
27+
* @return any byte except 0, which is reserved value
28+
*/
29+
byte id();
30+
31+
void writeKey(WorkflowOutputBuffer buffer);
32+
33+
String key();
34+
}

0 commit comments

Comments
 (0)