|
28 | 28 | import java.net.UnknownHostException;
|
29 | 29 | import java.util.ArrayList;
|
30 | 30 | import java.util.Arrays;
|
| 31 | +import java.util.Collection; |
31 | 32 | import java.util.Collections;
|
32 | 33 | import java.util.HashMap;
|
33 | 34 | import java.util.HashSet;
|
@@ -703,43 +704,31 @@ private CompactionCoordinatorService.Client getCoordinator(HostAndPort address)
|
703 | 704 | return coordinatorClient;
|
704 | 705 | }
|
705 | 706 |
|
706 |
| - private Map<HostAndPort,ScanStats> fetchTServerScans() { |
| 707 | + private Map<HostAndPort,ScanStats> fetchScans(Collection<String> servers) { |
707 | 708 | ServerContext context = getContext();
|
708 |
| - Map<HostAndPort,ScanStats> tserverScans = new HashMap<>(); |
709 |
| - final long now = System.currentTimeMillis(); |
710 |
| - for (String server : context.instanceOperations().getTabletServers()) { |
| 709 | + Map<HostAndPort,ScanStats> scans = new HashMap<>(); |
| 710 | + for (String server : servers) { |
711 | 711 | final HostAndPort parsedServer = HostAndPort.fromString(server);
|
712 |
| - TabletScanClientService.Client tserver = null; |
| 712 | + TabletScanClientService.Client client = null; |
713 | 713 | try {
|
714 |
| - tserver = ThriftUtil.getClient(ThriftClientTypes.TABLET_SCAN, parsedServer, context); |
715 |
| - List<ActiveScan> scans = tserver.getActiveScans(null, context.rpcCreds()); |
716 |
| - tserverScans.put(parsedServer, new ScanStats(scans)); |
| 714 | + client = ThriftUtil.getClient(ThriftClientTypes.TABLET_SCAN, parsedServer, context); |
| 715 | + List<ActiveScan> activeScans = client.getActiveScans(null, context.rpcCreds()); |
| 716 | + scans.put(parsedServer, new ScanStats(activeScans)); |
717 | 717 | } catch (Exception ex) {
|
718 | 718 | log.error("Failed to get active scans from {}", server, ex);
|
719 | 719 | } finally {
|
720 |
| - ThriftUtil.returnClient(tserver, context); |
| 720 | + ThriftUtil.returnClient(client, context); |
721 | 721 | }
|
722 | 722 | }
|
723 |
| - return Collections.unmodifiableMap(tserverScans); |
| 723 | + return Collections.unmodifiableMap(scans); |
| 724 | + } |
| 725 | + |
| 726 | + private Map<HostAndPort,ScanStats> fetchTServerScans() { |
| 727 | + return fetchScans(getContext().instanceOperations().getTabletServers()); |
724 | 728 | }
|
725 | 729 |
|
726 | 730 | private Map<HostAndPort,ScanStats> fetchSServerScans() {
|
727 |
| - ServerContext context = getContext(); |
728 |
| - Map<HostAndPort,ScanStats> sserverScans = new HashMap<>(); |
729 |
| - for (String server : context.instanceOperations().getScanServers()) { |
730 |
| - final HostAndPort parsedServer = HostAndPort.fromString(server); |
731 |
| - TabletScanClientService.Client sserver = null; |
732 |
| - try { |
733 |
| - sserver = ThriftUtil.getClient(ThriftClientTypes.TABLET_SCAN, parsedServer, context); |
734 |
| - List<ActiveScan> scans = sserver.getActiveScans(null, context.rpcCreds()); |
735 |
| - sserverScans.put(parsedServer, new ScanStats(scans)); |
736 |
| - } catch (Exception ex) { |
737 |
| - log.error("Failed to get active scans from {}", server, ex); |
738 |
| - } finally { |
739 |
| - ThriftUtil.returnClient(sserver, context); |
740 |
| - } |
741 |
| - } |
742 |
| - return Collections.unmodifiableMap(sserverScans); |
| 731 | + return fetchScans(getContext().instanceOperations().getScanServers()); |
743 | 732 | }
|
744 | 733 |
|
745 | 734 | private Map<HostAndPort,CompactionStats> fetchCompactions() {
|
|
0 commit comments