Committed by
Gerrit Code Review
Fix bug that true is always returned even in failure cases
Additionally, remove catch block handling TransactionException, which doesn't have to be caught in user side any more. Change-Id: I359b50dbe0e1074a2bc4c8850459cb4463669aa8
Showing
2 changed files
with
6 additions
and
43 deletions
... | @@ -29,7 +29,6 @@ import org.onosproject.store.service.ConsistentMap; | ... | @@ -29,7 +29,6 @@ import org.onosproject.store.service.ConsistentMap; |
29 | import org.onosproject.store.service.Serializer; | 29 | import org.onosproject.store.service.Serializer; |
30 | import org.onosproject.store.service.StorageService; | 30 | import org.onosproject.store.service.StorageService; |
31 | import org.onosproject.store.service.TransactionContext; | 31 | import org.onosproject.store.service.TransactionContext; |
32 | -import org.onosproject.store.service.TransactionException; | ||
33 | import org.onosproject.store.service.TransactionalMap; | 32 | import org.onosproject.store.service.TransactionalMap; |
34 | import org.onosproject.store.service.Versioned; | 33 | import org.onosproject.store.service.Versioned; |
35 | import org.slf4j.Logger; | 34 | import org.slf4j.Logger; |
... | @@ -100,7 +99,6 @@ public class ConsistentResourceStore implements ResourceStore { | ... | @@ -100,7 +99,6 @@ public class ConsistentResourceStore implements ResourceStore { |
100 | TransactionContext tx = service.transactionContextBuilder().build(); | 99 | TransactionContext tx = service.transactionContextBuilder().build(); |
101 | tx.begin(); | 100 | tx.begin(); |
102 | 101 | ||
103 | - try { | ||
104 | TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = | 102 | TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = |
105 | tx.getTransactionalMap(CHILD_MAP, SERIALIZER); | 103 | tx.getTransactionalMap(CHILD_MAP, SERIALIZER); |
106 | 104 | ||
... | @@ -118,11 +116,7 @@ public class ConsistentResourceStore implements ResourceStore { | ... | @@ -118,11 +116,7 @@ public class ConsistentResourceStore implements ResourceStore { |
118 | } | 116 | } |
119 | } | 117 | } |
120 | 118 | ||
121 | - return commitTransaction(tx); | 119 | + return tx.commit(); |
122 | - } catch (TransactionException e) { | ||
123 | - log.error("Exception thrown, abort the transaction", e); | ||
124 | - return abortTransaction(tx); | ||
125 | - } | ||
126 | } | 120 | } |
127 | 121 | ||
128 | @Override | 122 | @Override |
... | @@ -132,7 +126,6 @@ public class ConsistentResourceStore implements ResourceStore { | ... | @@ -132,7 +126,6 @@ public class ConsistentResourceStore implements ResourceStore { |
132 | TransactionContext tx = service.transactionContextBuilder().build(); | 126 | TransactionContext tx = service.transactionContextBuilder().build(); |
133 | tx.begin(); | 127 | tx.begin(); |
134 | 128 | ||
135 | - try { | ||
136 | TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = | 129 | TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = |
137 | tx.getTransactionalMap(CHILD_MAP, SERIALIZER); | 130 | tx.getTransactionalMap(CHILD_MAP, SERIALIZER); |
138 | TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = | 131 | TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = |
... | @@ -154,11 +147,7 @@ public class ConsistentResourceStore implements ResourceStore { | ... | @@ -154,11 +147,7 @@ public class ConsistentResourceStore implements ResourceStore { |
154 | } | 147 | } |
155 | } | 148 | } |
156 | 149 | ||
157 | - return commitTransaction(tx); | 150 | + return tx.commit(); |
158 | - } catch (TransactionException e) { | ||
159 | - log.error("Exception thrown, abort the transaction", e); | ||
160 | - return abortTransaction(tx); | ||
161 | - } | ||
162 | } | 151 | } |
163 | 152 | ||
164 | @Override | 153 | @Override |
... | @@ -169,7 +158,6 @@ public class ConsistentResourceStore implements ResourceStore { | ... | @@ -169,7 +158,6 @@ public class ConsistentResourceStore implements ResourceStore { |
169 | TransactionContext tx = service.transactionContextBuilder().build(); | 158 | TransactionContext tx = service.transactionContextBuilder().build(); |
170 | tx.begin(); | 159 | tx.begin(); |
171 | 160 | ||
172 | - try { | ||
173 | TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = | 161 | TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = |
174 | tx.getTransactionalMap(CHILD_MAP, SERIALIZER); | 162 | tx.getTransactionalMap(CHILD_MAP, SERIALIZER); |
175 | TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = | 163 | TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = |
... | @@ -186,11 +174,7 @@ public class ConsistentResourceStore implements ResourceStore { | ... | @@ -186,11 +174,7 @@ public class ConsistentResourceStore implements ResourceStore { |
186 | } | 174 | } |
187 | } | 175 | } |
188 | 176 | ||
189 | - return commitTransaction(tx); | 177 | + return tx.commit(); |
190 | - } catch (TransactionException e) { | ||
191 | - log.error("Exception thrown, abort the transaction", e); | ||
192 | - return abortTransaction(tx); | ||
193 | - } | ||
194 | } | 178 | } |
195 | 179 | ||
196 | @Override | 180 | @Override |
... | @@ -202,7 +186,6 @@ public class ConsistentResourceStore implements ResourceStore { | ... | @@ -202,7 +186,6 @@ public class ConsistentResourceStore implements ResourceStore { |
202 | TransactionContext tx = service.transactionContextBuilder().build(); | 186 | TransactionContext tx = service.transactionContextBuilder().build(); |
203 | tx.begin(); | 187 | tx.begin(); |
204 | 188 | ||
205 | - try { | ||
206 | TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = | 189 | TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = |
207 | tx.getTransactionalMap(CONSUMER_MAP, SERIALIZER); | 190 | tx.getTransactionalMap(CONSUMER_MAP, SERIALIZER); |
208 | Iterator<ResourcePath> resourceIte = resources.iterator(); | 191 | Iterator<ResourcePath> resourceIte = resources.iterator(); |
... | @@ -219,11 +202,7 @@ public class ConsistentResourceStore implements ResourceStore { | ... | @@ -219,11 +202,7 @@ public class ConsistentResourceStore implements ResourceStore { |
219 | } | 202 | } |
220 | } | 203 | } |
221 | 204 | ||
222 | - return commitTransaction(tx); | 205 | + return tx.commit(); |
223 | - } catch (TransactionException e) { | ||
224 | - log.error("Exception thrown, abort the transaction", e); | ||
225 | - return abortTransaction(tx); | ||
226 | - } | ||
227 | } | 206 | } |
228 | 207 | ||
229 | @Override | 208 | @Override |
... | @@ -278,17 +257,6 @@ public class ConsistentResourceStore implements ResourceStore { | ... | @@ -278,17 +257,6 @@ public class ConsistentResourceStore implements ResourceStore { |
278 | } | 257 | } |
279 | 258 | ||
280 | /** | 259 | /** |
281 | - * Commit the transaction. | ||
282 | - * | ||
283 | - * @param tx transaction context | ||
284 | - * @return always true | ||
285 | - */ | ||
286 | - private boolean commitTransaction(TransactionContext tx) { | ||
287 | - tx.commit(); | ||
288 | - return true; | ||
289 | - } | ||
290 | - | ||
291 | - /** | ||
292 | * Appends the values to the existing values associated with the specified key. | 260 | * Appends the values to the existing values associated with the specified key. |
293 | * If the map already has all the given values, appending will not happen. | 261 | * If the map already has all the given values, appending will not happen. |
294 | * | 262 | * | ... | ... |
... | @@ -59,7 +59,6 @@ import org.onosproject.store.service.ConsistentMap; | ... | @@ -59,7 +59,6 @@ import org.onosproject.store.service.ConsistentMap; |
59 | import org.onosproject.store.service.Serializer; | 59 | import org.onosproject.store.service.Serializer; |
60 | import org.onosproject.store.service.StorageService; | 60 | import org.onosproject.store.service.StorageService; |
61 | import org.onosproject.store.service.TransactionContext; | 61 | import org.onosproject.store.service.TransactionContext; |
62 | -import org.onosproject.store.service.TransactionException; | ||
63 | import org.onosproject.store.service.TransactionalMap; | 62 | import org.onosproject.store.service.TransactionalMap; |
64 | import org.onosproject.store.service.Versioned; | 63 | import org.onosproject.store.service.Versioned; |
65 | 64 | ||
... | @@ -294,7 +293,7 @@ public class ConsistentLinkResourceStore extends | ... | @@ -294,7 +293,7 @@ public class ConsistentLinkResourceStore extends |
294 | intentAllocs.put(allocations.intentId(), allocations); | 293 | intentAllocs.put(allocations.intentId(), allocations); |
295 | allocations.links().forEach(link -> allocateLinkResource(tx, link, allocations)); | 294 | allocations.links().forEach(link -> allocateLinkResource(tx, link, allocations)); |
296 | tx.commit(); | 295 | tx.commit(); |
297 | - } catch (TransactionException | ResourceAllocationException e) { | 296 | + } catch (ResourceAllocationException e) { |
298 | log.error("Exception thrown, rolling back", e); | 297 | log.error("Exception thrown, rolling back", e); |
299 | tx.abort(); | 298 | tx.abort(); |
300 | } catch (Exception e) { | 299 | } catch (Exception e) { |
... | @@ -407,11 +406,7 @@ public class ConsistentLinkResourceStore extends | ... | @@ -407,11 +406,7 @@ public class ConsistentLinkResourceStore extends |
407 | after.remove(allocations); | 406 | after.remove(allocations); |
408 | linkAllocs.replace(linkId, before, after); | 407 | linkAllocs.replace(linkId, before, after); |
409 | }); | 408 | }); |
410 | - tx.commit(); | 409 | + success = tx.commit(); |
411 | - success = true; | ||
412 | - } catch (TransactionException e) { | ||
413 | - log.debug("Transaction failed, retrying", e); | ||
414 | - tx.abort(); | ||
415 | } catch (Exception e) { | 410 | } catch (Exception e) { |
416 | log.error("Exception thrown during releaseResource {}", allocations, e); | 411 | log.error("Exception thrown during releaseResource {}", allocations, e); |
417 | tx.abort(); | 412 | tx.abort(); | ... | ... |
-
Please register or login to post a comment