beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [47/50] incubator-beam git commit: Use a int Sequence instead of a Random UUID for Aggregator IDs
Date Fri, 28 Oct 2016 14:48:21 GMT
Use a int Sequence instead of a Random UUID for Aggregator IDs

Aggregator IDs are used to ensure that an Aggregator's identity is
consistent across synchronization barriers. This is only relevant when
constructing the map of Step -> Aggregator to enable querying, as the
DoFns represented within the graph may be serialized. The identity has
no impact on the interaction between the runner and aggregator, which is
the responsibility of the ProcessContext object and

UUID#randomUUID uses a shared SecureRandom to create the bytes of the
UUID; SecureRandom#nextBytes is a synchronized method, so regardless of
the underlying source of randomness, only one random UUID can be
generated at a time. Instead, use an atomically increasing int to
identify aggregators. This should be sufficient for user-created
aggregators, and system aggregators should not care about the id.


Branch: refs/heads/apex-runner
Commit: dd854b1a71770b9b452361e0d92e018b65f1b3e8
Parents: f2ec824
Author: Thomas Groh <>
Authored: Thu Oct 27 10:19:03 2016 -0700
Committer: Dan Halperin <>
Committed: Thu Oct 27 16:28:32 2016 -0700

 .../org/apache/beam/sdk/transforms/  | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/
index d92bb71..e03d3b1 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/
@@ -22,7 +22,7 @@ import static;
 import java.util.Objects;
-import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.beam.sdk.transforms.Combine.CombineFn;
@@ -37,7 +37,8 @@ import org.apache.beam.sdk.transforms.Combine.CombineFn;
 class DelegatingAggregator<AggInputT, AggOutputT>
     implements Aggregator<AggInputT, AggOutputT>, Serializable {
-  private final UUID id;
+  private static final AtomicInteger ID_GEN = new AtomicInteger();
+  private final int id;
   private final String name;
@@ -47,7 +48,7 @@ class DelegatingAggregator<AggInputT, AggOutputT>
   public DelegatingAggregator(String name,
       CombineFn<? super AggInputT, ?, AggOutputT> combiner) {
- = UUID.randomUUID();
+ = ID_GEN.getAndIncrement(); = checkNotNull(name, "name cannot be null");
     // Safe contravariant cast

View raw message