Skip to content

Commit

Permalink
FAB-7009 Send orderer provide exception
Browse files Browse the repository at this point in the history
PS
4 Shuffle orderers case first always is failing and provide load balancing.
5 Minor tweak Arraylist probably faster for this.

Change-Id: Idcdaaa02a61198b4e55090743ba83ea28e184278
Signed-off-by: rickr <cr22rc@gmail.com>
  • Loading branch information
cr22rc committed Nov 16, 2017
1 parent ef748a8 commit a8d8951
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/main/java/org/hyperledger/fabric/sdk/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2362,7 +2362,11 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe
if (null == orderers) {
throw new InvalidArgumentException("sendTransaction Orderers is null");
}
if (orderers.isEmpty()) {

final ArrayList<Orderer> shuffeldOrderers = new ArrayList<>(orderers);
Collections.shuffle(shuffeldOrderers);

if (shuffeldOrderers.isEmpty()) {
throw new InvalidArgumentException("sendTransaction Orderers to send to is empty.");
}

Expand Down Expand Up @@ -2415,9 +2419,10 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe

logger.debug(format("Channel %s sending transaction to orderer(s) with TxID %s ", name, proposalTransactionID));
boolean success = false;
Exception lException = null; // Save last exception to report to user .. others are just logged.

BroadcastResponse resp = null;
for (Orderer orderer : orderers) {
for (Orderer orderer : shuffeldOrderers) {
try {

if (null != diagnosticFileDumper) {
Expand All @@ -2426,25 +2431,30 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe
}

resp = orderer.sendTransaction(transactionEnvelope);
lException = null; // no longer last exception .. maybe just failed.
if (resp.getStatus() == Status.SUCCESS) {
success = true;
break;
}
} catch (Exception e) {
String emsg = format("Channel %s unsuccessful sendTransaction to orderer", name);
String emsg = format("Channel %s unsuccessful sendTransaction to orderer %s (%s)",
name, orderer.getName(), orderer.getUrl());
if (resp != null) {

emsg = format("Channel %s unsuccessful sendTransaction to orderer. %s", name, getRespData(resp));
emsg = format("Channel %s unsuccessful sendTransaction to orderer %s (%s). %s",
name, orderer.getName(), orderer.getUrl(), getRespData(resp));
}

logger.error(emsg, e);
lException = new Exception(emsg, e);

}

}

if (success) {
logger.debug(format("Channel %s successful sent to Orderer transaction id: %s", name, proposalTransactionID));
logger.debug(format("Channel %s successful sent to Orderer transaction id: %s",
name, proposalTransactionID));
return sret;
} else {

Expand All @@ -2454,7 +2464,7 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe
unregisterTxListener(proposalTransactionID);

CompletableFuture<TransactionEvent> ret = new CompletableFuture<>();
ret.completeExceptionally(new Exception(emsg));
ret.completeExceptionally(lException != null ? new Exception(emsg, lException) : new Exception(emsg));
return ret;
}
} catch (Exception e) {
Expand All @@ -2469,6 +2479,7 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe

/**
* Build response details
*
* @param resp
* @return
*/
Expand Down

0 comments on commit a8d8951

Please sign in to comment.