Committed by
Ray Milkey
Return immediately when the given BatchWrite is empty
This revision aims to remove empty check of BatchWrite in the caller side of this method Change-Id: Ic0d659a6da221a052ad135eba18a783caa81ec42
Showing
4 changed files
with
15 additions
and
0 deletions
... | @@ -112,6 +112,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { | ... | @@ -112,6 +112,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { |
112 | 112 | ||
113 | /** | 113 | /** |
114 | * Execute writes in a batch. | 114 | * Execute writes in a batch. |
115 | + * If the specified BatchWrite is empty, write will not be executed. | ||
115 | * | 116 | * |
116 | * @param batch BatchWrite to execute | 117 | * @param batch BatchWrite to execute |
117 | * @return failed operations | 118 | * @return failed operations | ... | ... |
... | @@ -54,6 +54,7 @@ import org.onlab.util.KryoNamespace; | ... | @@ -54,6 +54,7 @@ import org.onlab.util.KryoNamespace; |
54 | import org.slf4j.Logger; | 54 | import org.slf4j.Logger; |
55 | 55 | ||
56 | import java.util.ArrayList; | 56 | import java.util.ArrayList; |
57 | +import java.util.Collections; | ||
57 | import java.util.EnumSet; | 58 | import java.util.EnumSet; |
58 | import java.util.HashSet; | 59 | import java.util.HashSet; |
59 | import java.util.List; | 60 | import java.util.List; |
... | @@ -416,6 +417,9 @@ public class DistributedIntentStore | ... | @@ -416,6 +417,9 @@ public class DistributedIntentStore |
416 | 417 | ||
417 | @Override | 418 | @Override |
418 | public List<Operation> batchWrite(BatchWrite batch) { | 419 | public List<Operation> batchWrite(BatchWrite batch) { |
420 | + if (batch.isEmpty()) { | ||
421 | + return Collections.emptyList(); | ||
422 | + } | ||
419 | 423 | ||
420 | List<Operation> failed = new ArrayList<>(); | 424 | List<Operation> failed = new ArrayList<>(); |
421 | final Builder builder = BatchWriteRequest.newBuilder(); | 425 | final Builder builder = BatchWriteRequest.newBuilder(); | ... | ... |
... | @@ -54,6 +54,7 @@ import org.onlab.util.KryoNamespace; | ... | @@ -54,6 +54,7 @@ import org.onlab.util.KryoNamespace; |
54 | import org.slf4j.Logger; | 54 | import org.slf4j.Logger; |
55 | 55 | ||
56 | import java.util.ArrayList; | 56 | import java.util.ArrayList; |
57 | +import java.util.Collections; | ||
57 | import java.util.EnumSet; | 58 | import java.util.EnumSet; |
58 | import java.util.List; | 59 | import java.util.List; |
59 | import java.util.Map; | 60 | import java.util.Map; |
... | @@ -394,6 +395,10 @@ public class HazelcastIntentStore | ... | @@ -394,6 +395,10 @@ public class HazelcastIntentStore |
394 | 395 | ||
395 | @Override | 396 | @Override |
396 | public List<Operation> batchWrite(BatchWrite batch) { | 397 | public List<Operation> batchWrite(BatchWrite batch) { |
398 | + if (batch.isEmpty()) { | ||
399 | + return Collections.emptyList(); | ||
400 | + } | ||
401 | + | ||
397 | // Hazelcast version will never fail for conditional failure now. | 402 | // Hazelcast version will never fail for conditional failure now. |
398 | List<Operation> failed = new ArrayList<>(); | 403 | List<Operation> failed = new ArrayList<>(); |
399 | 404 | ... | ... |
... | @@ -33,6 +33,7 @@ import org.onosproject.net.intent.BatchWrite.Operation; | ... | @@ -33,6 +33,7 @@ import org.onosproject.net.intent.BatchWrite.Operation; |
33 | import org.onosproject.store.AbstractStore; | 33 | import org.onosproject.store.AbstractStore; |
34 | import org.slf4j.Logger; | 34 | import org.slf4j.Logger; |
35 | 35 | ||
36 | +import java.util.Collections; | ||
36 | import java.util.List; | 37 | import java.util.List; |
37 | import java.util.Map; | 38 | import java.util.Map; |
38 | import java.util.concurrent.ConcurrentHashMap; | 39 | import java.util.concurrent.ConcurrentHashMap; |
... | @@ -154,6 +155,10 @@ public class SimpleIntentStore | ... | @@ -154,6 +155,10 @@ public class SimpleIntentStore |
154 | */ | 155 | */ |
155 | @Override | 156 | @Override |
156 | public List<Operation> batchWrite(BatchWrite batch) { | 157 | public List<Operation> batchWrite(BatchWrite batch) { |
158 | + if (batch.isEmpty()) { | ||
159 | + return Collections.emptyList(); | ||
160 | + } | ||
161 | + | ||
157 | List<Operation> failed = Lists.newArrayList(); | 162 | List<Operation> failed = Lists.newArrayList(); |
158 | for (Operation op : batch.operations()) { | 163 | for (Operation op : batch.operations()) { |
159 | switch (op.type()) { | 164 | switch (op.type()) { | ... | ... |
-
Please register or login to post a comment