Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit a8d8951

Browse files
committed
FAB-7009 Send orderer provide exception
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>
1 parent ef748a8 commit a8d8951

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/main/java/org/hyperledger/fabric/sdk/Channel.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,7 +2362,11 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe
23622362
if (null == orderers) {
23632363
throw new InvalidArgumentException("sendTransaction Orderers is null");
23642364
}
2365-
if (orderers.isEmpty()) {
2365+
2366+
final ArrayList<Orderer> shuffeldOrderers = new ArrayList<>(orderers);
2367+
Collections.shuffle(shuffeldOrderers);
2368+
2369+
if (shuffeldOrderers.isEmpty()) {
23662370
throw new InvalidArgumentException("sendTransaction Orderers to send to is empty.");
23672371
}
23682372

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

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

24192424
BroadcastResponse resp = null;
2420-
for (Orderer orderer : orderers) {
2425+
for (Orderer orderer : shuffeldOrderers) {
24212426
try {
24222427

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

24282433
resp = orderer.sendTransaction(transactionEnvelope);
2434+
lException = null; // no longer last exception .. maybe just failed.
24292435
if (resp.getStatus() == Status.SUCCESS) {
24302436
success = true;
24312437
break;
24322438
}
24332439
} catch (Exception e) {
2434-
String emsg = format("Channel %s unsuccessful sendTransaction to orderer", name);
2440+
String emsg = format("Channel %s unsuccessful sendTransaction to orderer %s (%s)",
2441+
name, orderer.getName(), orderer.getUrl());
24352442
if (resp != null) {
24362443

2437-
emsg = format("Channel %s unsuccessful sendTransaction to orderer. %s", name, getRespData(resp));
2444+
emsg = format("Channel %s unsuccessful sendTransaction to orderer %s (%s). %s",
2445+
name, orderer.getName(), orderer.getUrl(), getRespData(resp));
24382446
}
24392447

24402448
logger.error(emsg, e);
2449+
lException = new Exception(emsg, e);
24412450

24422451
}
24432452

24442453
}
24452454

24462455
if (success) {
2447-
logger.debug(format("Channel %s successful sent to Orderer transaction id: %s", name, proposalTransactionID));
2456+
logger.debug(format("Channel %s successful sent to Orderer transaction id: %s",
2457+
name, proposalTransactionID));
24482458
return sret;
24492459
} else {
24502460

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

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

24702480
/**
24712481
* Build response details
2482+
*
24722483
* @param resp
24732484
* @return
24742485
*/

0 commit comments

Comments
 (0)