Sho SHIMIZU
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
......@@ -29,7 +29,6 @@ import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
import org.onosproject.store.service.TransactionContext;
import org.onosproject.store.service.TransactionException;
import org.onosproject.store.service.TransactionalMap;
import org.onosproject.store.service.Versioned;
import org.slf4j.Logger;
......@@ -100,7 +99,6 @@ public class ConsistentResourceStore implements ResourceStore {
TransactionContext tx = service.transactionContextBuilder().build();
tx.begin();
try {
TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap =
tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
......@@ -118,11 +116,7 @@ public class ConsistentResourceStore implements ResourceStore {
}
}
return commitTransaction(tx);
} catch (TransactionException e) {
log.error("Exception thrown, abort the transaction", e);
return abortTransaction(tx);
}
return tx.commit();
}
@Override
......@@ -132,7 +126,6 @@ public class ConsistentResourceStore implements ResourceStore {
TransactionContext tx = service.transactionContextBuilder().build();
tx.begin();
try {
TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap =
tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap =
......@@ -154,11 +147,7 @@ public class ConsistentResourceStore implements ResourceStore {
}
}
return commitTransaction(tx);
} catch (TransactionException e) {
log.error("Exception thrown, abort the transaction", e);
return abortTransaction(tx);
}
return tx.commit();
}
@Override
......@@ -169,7 +158,6 @@ public class ConsistentResourceStore implements ResourceStore {
TransactionContext tx = service.transactionContextBuilder().build();
tx.begin();
try {
TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap =
tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap =
......@@ -186,11 +174,7 @@ public class ConsistentResourceStore implements ResourceStore {
}
}
return commitTransaction(tx);
} catch (TransactionException e) {
log.error("Exception thrown, abort the transaction", e);
return abortTransaction(tx);
}
return tx.commit();
}
@Override
......@@ -202,7 +186,6 @@ public class ConsistentResourceStore implements ResourceStore {
TransactionContext tx = service.transactionContextBuilder().build();
tx.begin();
try {
TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap =
tx.getTransactionalMap(CONSUMER_MAP, SERIALIZER);
Iterator<ResourcePath> resourceIte = resources.iterator();
......@@ -219,11 +202,7 @@ public class ConsistentResourceStore implements ResourceStore {
}
}
return commitTransaction(tx);
} catch (TransactionException e) {
log.error("Exception thrown, abort the transaction", e);
return abortTransaction(tx);
}
return tx.commit();
}
@Override
......@@ -278,17 +257,6 @@ public class ConsistentResourceStore implements ResourceStore {
}
/**
* Commit the transaction.
*
* @param tx transaction context
* @return always true
*/
private boolean commitTransaction(TransactionContext tx) {
tx.commit();
return true;
}
/**
* Appends the values to the existing values associated with the specified key.
* If the map already has all the given values, appending will not happen.
*
......
......@@ -59,7 +59,6 @@ import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
import org.onosproject.store.service.TransactionContext;
import org.onosproject.store.service.TransactionException;
import org.onosproject.store.service.TransactionalMap;
import org.onosproject.store.service.Versioned;
......@@ -294,7 +293,7 @@ public class ConsistentLinkResourceStore extends
intentAllocs.put(allocations.intentId(), allocations);
allocations.links().forEach(link -> allocateLinkResource(tx, link, allocations));
tx.commit();
} catch (TransactionException | ResourceAllocationException e) {
} catch (ResourceAllocationException e) {
log.error("Exception thrown, rolling back", e);
tx.abort();
} catch (Exception e) {
......@@ -407,11 +406,7 @@ public class ConsistentLinkResourceStore extends
after.remove(allocations);
linkAllocs.replace(linkId, before, after);
});
tx.commit();
success = true;
} catch (TransactionException e) {
log.debug("Transaction failed, retrying", e);
tx.abort();
success = tx.commit();
} catch (Exception e) {
log.error("Exception thrown during releaseResource {}", allocations, e);
tx.abort();
......