Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6C114200C72 for ; Fri, 12 May 2017 16:59:47 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6A9A2160BD6; Fri, 12 May 2017 14:59:47 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E37CD160BA3 for ; Fri, 12 May 2017 16:59:44 +0200 (CEST) Received: (qmail 47825 invoked by uid 500); 12 May 2017 14:59:38 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 45914 invoked by uid 99); 12 May 2017 14:59:36 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 May 2017 14:59:36 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5FA65E038B; Fri, 12 May 2017 14:59:36 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: git-site-role@apache.org To: commits@hbase.apache.org Date: Fri, 12 May 2017 14:59:55 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [21/51] [partial] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd. archived-at: Fri, 12 May 2017 14:59:47 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/709b8fcc/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.EnableTableFuture.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.EnableTableFuture.html b/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.EnableTableFuture.html index f2c44db..6cf2fc8 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.EnableTableFuture.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.EnableTableFuture.html @@ -2581,7 +2581,7 @@ 2573 try { 2574 // Restore snapshot 2575 get( -2576 internalRestoreSnapshotAsync(snapshotName, tableName, false), +2576 internalRestoreSnapshotAsync(snapshotName, tableName), 2577 syncWaitTimeout, 2578 TimeUnit.MILLISECONDS); 2579 } catch (IOException e) { @@ -2590,7 +2590,7 @@ 2582 if (takeFailSafeSnapshot) { 2583 try { 2584 get( -2585 internalRestoreSnapshotAsync(failSafeSnapshotSnapshotName, tableName, false), +2585 internalRestoreSnapshotAsync(failSafeSnapshotSnapshotName, tableName), 2586 syncWaitTimeout, 2587 TimeUnit.MILLISECONDS); 2588 String msg = "Restore snapshot=" + snapshotName + @@ -2633,7 +2633,7 @@ 2625 throw new TableNotDisabledException(tableName); 2626 } 2627 -2628 return internalRestoreSnapshotAsync(snapshotName, tableName, false); +2628 return internalRestoreSnapshotAsync(snapshotName, tableName); 2629 } 2630 2631 @Override @@ -2643,1621 +2643,1614 @@ 2635 } 2636 2637 @Override -2638 public void cloneSnapshot(String snapshotName, TableName tableName, boolean restoreAcl) +2638 public void cloneSnapshot(final String snapshotName, final TableName tableName) 2639 throws IOException, TableExistsException, RestoreSnapshotException { 2640 if (tableExists(tableName)) { 2641 throw new TableExistsException(tableName); 2642 } 2643 get( -2644 internalRestoreSnapshotAsync(snapshotName, tableName, restoreAcl), +2644 internalRestoreSnapshotAsync(snapshotName, tableName), 2645 Integer.MAX_VALUE, 2646 TimeUnit.MILLISECONDS); 2647 } 2648 2649 @Override -2650 public void cloneSnapshot(final String snapshotName, final TableName tableName) -2651 throws IOException, TableExistsException, RestoreSnapshotException { -2652 cloneSnapshot(snapshotName, tableName, false); -2653 } -2654 -2655 @Override -2656 public Future<Void> cloneSnapshotAsync(final String snapshotName, final TableName tableName) -2657 throws IOException, TableExistsException { -2658 if (tableExists(tableName)) { -2659 throw new TableExistsException(tableName); -2660 } -2661 return internalRestoreSnapshotAsync(snapshotName, tableName, false); -2662 } -2663 -2664 @Override -2665 public byte[] execProcedureWithRet(String signature, String instance, Map<String, String> props) -2666 throws IOException { -2667 ProcedureDescription desc = ProtobufUtil.buildProcedureDescription(signature, instance, props); -2668 final ExecProcedureRequest request = -2669 ExecProcedureRequest.newBuilder().setProcedure(desc).build(); -2670 // run the procedure on the master -2671 ExecProcedureResponse response = executeCallable( -2672 new MasterCallable<ExecProcedureResponse>(getConnection(), getRpcControllerFactory()) { -2673 @Override -2674 protected ExecProcedureResponse rpcCall() throws Exception { -2675 return master.execProcedureWithRet(getRpcController(), request); -2676 } -2677 }); -2678 -2679 return response.hasReturnData() ? response.getReturnData().toByteArray() : null; -2680 } -2681 -2682 @Override -2683 public void execProcedure(String signature, String instance, Map<String, String> props) -2684 throws IOException { -2685 ProcedureDescription desc = ProtobufUtil.buildProcedureDescription(signature, instance, props); -2686 final ExecProcedureRequest request = -2687 ExecProcedureRequest.newBuilder().setProcedure(desc).build(); -2688 // run the procedure on the master -2689 ExecProcedureResponse response = executeCallable(new MasterCallable<ExecProcedureResponse>( -2690 getConnection(), getRpcControllerFactory()) { -2691 @Override -2692 protected ExecProcedureResponse rpcCall() throws Exception { -2693 return master.execProcedure(getRpcController(), request); -2694 } -2695 }); -2696 -2697 long start = EnvironmentEdgeManager.currentTime(); -2698 long max = response.getExpectedTimeout(); -2699 long maxPauseTime = max / this.numRetries; -2700 int tries = 0; -2701 LOG.debug("Waiting a max of " + max + " ms for procedure '" + -2702 signature + " : " + instance + "'' to complete. (max " + maxPauseTime + " ms per retry)"); -2703 boolean done = false; -2704 while (tries == 0 -2705 || ((EnvironmentEdgeManager.currentTime() - start) < max && !done)) { -2706 try { -2707 // sleep a backoff <= pauseTime amount -2708 long sleep = getPauseTime(tries++); -2709 sleep = sleep > maxPauseTime ? maxPauseTime : sleep; -2710 LOG.debug("(#" + tries + ") Sleeping: " + sleep + -2711 "ms while waiting for procedure completion."); -2712 Thread.sleep(sleep); -2713 } catch (InterruptedException e) { -2714 throw (InterruptedIOException)new InterruptedIOException("Interrupted").initCause(e); -2715 } -2716 LOG.debug("Getting current status of procedure from master..."); -2717 done = isProcedureFinished(signature, instance, props); -2718 } -2719 if (!done) { -2720 throw new IOException("Procedure '" + signature + " : " + instance -2721 + "' wasn't completed in expectedTime:" + max + " ms"); -2722 } -2723 } -2724 -2725 @Override -2726 public boolean isProcedureFinished(String signature, String instance, Map<String, String> props) -2727 throws IOException { -2728 ProcedureDescription desc = ProtobufUtil.buildProcedureDescription(signature, instance, props); -2729 return executeCallable( -2730 new MasterCallable<IsProcedureDoneResponse>(getConnection(), getRpcControllerFactory()) { -2731 @Override -2732 protected IsProcedureDoneResponse rpcCall() throws Exception { -2733 return master.isProcedureDone(getRpcController(), -2734 IsProcedureDoneRequest.newBuilder().setProcedure(desc).build()); -2735 } -2736 }).getDone(); -2737 } -2738 -2739 /** -2740 * Execute Restore/Clone snapshot and wait for the server to complete (blocking). -2741 * To check if the cloned table exists, use {@link #isTableAvailable} -- it is not safe to -2742 * create an HTable instance to this table before it is available. -2743 * @param snapshotName snapshot to restore -2744 * @param tableName table name to restore the snapshot on -2745 * @throws IOException if a remote or network exception occurs -2746 * @throws RestoreSnapshotException if snapshot failed to be restored -2747 * @throws IllegalArgumentException if the restore request is formatted incorrectly -2748 */ -2749 private Future<Void> internalRestoreSnapshotAsync(final String snapshotName, -2750 final TableName tableName, final boolean restoreAcl) -2751 throws IOException, RestoreSnapshotException { -2752 final HBaseProtos.SnapshotDescription snapshot = HBaseProtos.SnapshotDescription.newBuilder() -2753 .setName(snapshotName).setTable(tableName.getNameAsString()).build(); -2754 -2755 // actually restore the snapshot -2756 ClientSnapshotDescriptionUtils.assertSnapshotRequestIsValid(snapshot); -2757 -2758 RestoreSnapshotResponse response = executeCallable( -2759 new MasterCallable<RestoreSnapshotResponse>(getConnection(), getRpcControllerFactory()) { -2760 @Override -2761 protected RestoreSnapshotResponse rpcCall() throws Exception { -2762 final RestoreSnapshotRequest request = RestoreSnapshotRequest.newBuilder() -2763 .setSnapshot(snapshot) -2764 .setNonceGroup(ng.getNonceGroup()) -2765 .setNonce(ng.newNonce()) -2766 .setRestoreACL(restoreAcl) -2767 .build(); -2768 return master.restoreSnapshot(getRpcController(), request); -2769 } -2770 }); -2771 -2772 return new RestoreSnapshotFuture(this, snapshot, tableName, response); -2773 } -2774 -2775 private static class RestoreSnapshotFuture extends TableFuture<Void> { -2776 public RestoreSnapshotFuture( -2777 final HBaseAdmin admin, -2778 final HBaseProtos.SnapshotDescription snapshot, -2779 final TableName tableName, -2780 final RestoreSnapshotResponse response) { -2781 super(admin, tableName, -2782 (response != null && response.hasProcId()) ? response.getProcId() : null); -2783 -2784 if (response != null && !response.hasProcId()) { -2785 throw new UnsupportedOperationException("Client could not call old version of Server"); -2786 } +2650 public Future<Void> cloneSnapshotAsync(final String snapshotName, final TableName tableName) +2651 throws IOException, TableExistsException { +2652 if (tableExists(tableName)) { +2653 throw new TableExistsException(tableName); +2654 } +2655 return internalRestoreSnapshotAsync(snapshotName, tableName); +2656 } +2657 +2658 @Override +2659 public byte[] execProcedureWithRet(String signature, String instance, Map<String, String> props) +2660 throws IOException { +2661 ProcedureDescription desc = ProtobufUtil.buildProcedureDescription(signature, instance, props); +2662 final ExecProcedureRequest request = +2663 ExecProcedureRequest.newBuilder().setProcedure(desc).build(); +2664 // run the procedure on the master +2665 ExecProcedureResponse response = executeCallable( +2666 new MasterCallable<ExecProcedureResponse>(getConnection(), getRpcControllerFactory()) { +2667 @Override +2668 protected ExecProcedureResponse rpcCall() throws Exception { +2669 return master.execProcedureWithRet(getRpcController(), request); +2670 } +2671 }); +2672 +2673 return response.hasReturnData() ? response.getReturnData().toByteArray() : null; +2674 } +2675 +2676 @Override +2677 public void execProcedure(String signature, String instance, Map<String, String> props) +2678 throws IOException { +2679 ProcedureDescription desc = ProtobufUtil.buildProcedureDescription(signature, instance, props); +2680 final ExecProcedureRequest request = +2681 ExecProcedureRequest.newBuilder().setProcedure(desc).build(); +2682 // run the procedure on the master +2683 ExecProcedureResponse response = executeCallable(new MasterCallable<ExecProcedureResponse>( +2684 getConnection(), getRpcControllerFactory()) { +2685 @Override +2686 protected ExecProcedureResponse rpcCall() throws Exception { +2687 return master.execProcedure(getRpcController(), request); +2688 } +2689 }); +2690 +2691 long start = EnvironmentEdgeManager.currentTime(); +2692 long max = response.getExpectedTimeout(); +2693 long maxPauseTime = max / this.numRetries; +2694 int tries = 0; +2695 LOG.debug("Waiting a max of " + max + " ms for procedure '" + +2696 signature + " : " + instance + "'' to complete. (max " + maxPauseTime + " ms per retry)"); +2697 boolean done = false; +2698 while (tries == 0 +2699 || ((EnvironmentEdgeManager.currentTime() - start) < max && !done)) { +2700 try { +2701 // sleep a backoff <= pauseTime amount +2702 long sleep = getPauseTime(tries++); +2703 sleep = sleep > maxPauseTime ? maxPauseTime : sleep; +2704 LOG.debug("(#" + tries + ") Sleeping: " + sleep + +2705 "ms while waiting for procedure completion."); +2706 Thread.sleep(sleep); +2707 } catch (InterruptedException e) { +2708 throw (InterruptedIOException)new InterruptedIOException("Interrupted").initCause(e); +2709 } +2710 LOG.debug("Getting current status of procedure from master..."); +2711 done = isProcedureFinished(signature, instance, props); +2712 } +2713 if (!done) { +2714 throw new IOException("Procedure '" + signature + " : " + instance +2715 + "' wasn't completed in expectedTime:" + max + " ms"); +2716 } +2717 } +2718 +2719 @Override +2720 public boolean isProcedureFinished(String signature, String instance, Map<String, String> props) +2721 throws IOException { +2722 ProcedureDescription desc = ProtobufUtil.buildProcedureDescription(signature, instance, props); +2723 return executeCallable( +2724 new MasterCallable<IsProcedureDoneResponse>(getConnection(), getRpcControllerFactory()) { +2725 @Override +2726 protected IsProcedureDoneResponse rpcCall() throws Exception { +2727 return master.isProcedureDone(getRpcController(), +2728 IsProcedureDoneRequest.newBuilder().setProcedure(desc).build()); +2729 } +2730 }).getDone(); +2731 } +2732 +2733 /** +2734 * Execute Restore/Clone snapshot and wait for the server to complete (blocking). +2735 * To check if the cloned table exists, use {@link #isTableAvailable} -- it is not safe to +2736 * create an HTable instance to this table before it is available. +2737 * @param snapshotName snapshot to restore +2738 * @param tableName table name to restore the snapshot on +2739 * @throws IOException if a remote or network exception occurs +2740 * @throws RestoreSnapshotException if snapshot failed to be restored +2741 * @throws IllegalArgumentException if the restore request is formatted incorrectly +2742 */ +2743 private Future<Void> internalRestoreSnapshotAsync( +2744 final String snapshotName, +2745 final TableName tableName) throws IOException, RestoreSnapshotException { +2746 final HBaseProtos.SnapshotDescription snapshot = HBaseProtos.SnapshotDescription.newBuilder() +2747 .setName(snapshotName).setTable(tableName.getNameAsString()).build(); +2748 +2749 // actually restore the snapshot +2750 ClientSnapshotDescriptionUtils.assertSnapshotRequestIsValid(snapshot); +2751 +2752 RestoreSnapshotResponse response = executeCallable( +2753 new MasterCallable<RestoreSnapshotResponse>(getConnection(), getRpcControllerFactory()) { +2754 @Override +2755 protected RestoreSnapshotResponse rpcCall() throws Exception { +2756 final RestoreSnapshotRequest request = RestoreSnapshotRequest.newBuilder() +2757 .setSnapshot(snapshot) +2758 .setNonceGroup(ng.getNonceGroup()) +2759 .setNonce(ng.newNonce()) +2760 .build(); +2761 return master.restoreSnapshot(getRpcController(), request); +2762 } +2763 }); +2764 +2765 return new RestoreSnapshotFuture(this, snapshot, tableName, response); +2766 } +2767 +2768 private static class RestoreSnapshotFuture extends TableFuture<Void> { +2769 public RestoreSnapshotFuture( +2770 final HBaseAdmin admin, +2771 final HBaseProtos.SnapshotDescription snapshot, +2772 final TableName tableName, +2773 final RestoreSnapshotResponse response) { +2774 super(admin, tableName, +2775 (response != null && response.hasProcId()) ? response.getProcId() : null); +2776 +2777 if (response != null && !response.hasProcId()) { +2778 throw new UnsupportedOperationException("Client could not call old version of Server"); +2779 } +2780 } +2781 +2782 public RestoreSnapshotFuture( +2783 final HBaseAdmin admin, +2784 final TableName tableName, +2785 final Long procId) { +2786 super(admin, tableName, procId); 2787 } 2788 -2789 public RestoreSnapshotFuture( -2790 final HBaseAdmin admin, -2791 final TableName tableName, -2792 final Long procId) { -2793 super(admin, tableName, procId); -2794 } -2795 -2796 @Override -2797 public String getOperationType() { -2798 return "MODIFY"; -2799 } -2800 } -2801 -2802 @Override -2803 public List<SnapshotDescription> listSnapshots() throws IOException { -2804 return executeCallable(new MasterCallable<List<SnapshotDescription>>(getConnection(), -2805 getRpcControllerFactory()) { -2806 @Override -2807 protected List<SnapshotDescription> rpcCall() throws Exception { -2808 List<HBaseProtos.SnapshotDescription> snapshotsList = master -2809 .getCompletedSnapshots(getRpcController(), -2810 GetCompletedSnapshotsRequest.newBuilder().build()) -2811 .getSnapshotsList(); -2812 List<SnapshotDescription> result = new ArrayList<>(snapshotsList.size()); -2813 for (HBaseProtos.SnapshotDescription snapshot : snapshotsList) { -2814 result.add(ProtobufUtil.createSnapshotDesc(snapshot)); -2815 } -2816 return result; -2817 } -2818 }); -2819 } -2820 -2821 @Override -2822 public List<SnapshotDescription> listSnapshots(String regex) throws IOException { -2823 return listSnapshots(Pattern.compile(regex)); -2824 } -2825 -2826 @Override -2827 public List<SnapshotDescription> listSnapshots(Pattern pattern) throws IOException { -2828 List<SnapshotDescription> matched = new LinkedList<>(); -2829 List<SnapshotDescription> snapshots = listSnapshots(); -2830 for (SnapshotDescription snapshot : snapshots) { -2831 if (pattern.matcher(snapshot.getName()).matches()) { -2832 matched.add(snapshot); -2833 } -2834 } -2835 return matched; -2836 } -2837 -2838 @Override -2839 public List<SnapshotDescription> listTableSnapshots(String tableNameRegex, -2840 String snapshotNameRegex) throws IOException { -2841 return listTableSnapshots(Pattern.compile(tableNameRegex), Pattern.compile(snapshotNameRegex)); -2842 } -2843 -2844 @Override -2845 public List<SnapshotDescription> listTableSnapshots(Pattern tableNamePattern, -2846 Pattern snapshotNamePattern) throws IOException { -2847 TableName[] tableNames = listTableNames(tableNamePattern); -2848 -2849 List<SnapshotDescription> tableSnapshots = new LinkedList<>(); -2850 List<SnapshotDescription> snapshots = listSnapshots(snapshotNamePattern); -2851 -2852 List<TableName> listOfTableNames = Arrays.asList(tableNames); -2853 for (SnapshotDescription snapshot : snapshots) { -2854 if (listOfTableNames.contains(snapshot.getTableName())) { -2855 tableSnapshots.add(snapshot); -2856 } -2857 } -2858 return tableSnapshots; -2859 } -2860 -2861 @Override -2862 public void deleteSnapshot(final byte[] snapshotName) throws IOException { -2863 deleteSnapshot(Bytes.toString(snapshotName)); -2864 } -2865 -2866 @Override -2867 public void deleteSnapshot(final String snapshotName) throws IOException { -2868 // make sure the snapshot is possibly valid -2869 TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(snapshotName)); -2870 // do the delete -2871 executeCallable(new MasterCallable<Void>(getConnection(), getRpcControllerFactory()) { -2872 @Override -2873 protected Void rpcCall() throws Exception { -2874 master.deleteSnapshot(getRpcController(), -2875 DeleteSnapshotRequest.newBuilder().setSnapshot( -2876 HBaseProtos.SnapshotDescription.newBuilder().setName(snapshotName).build()) -2877 .build() -2878 ); -2879 return null; -2880 } -2881 }); -2882 } -2883 -2884 @Override -2885 public void deleteSnapshots(final String regex) throws IOException { -2886 deleteSnapshots(Pattern.compile(regex)); -2887 } -2888 -2889 @Override -2890 public void deleteSnapshots(final Pattern pattern) throws IOException { -2891 List<SnapshotDescription> snapshots = listSnapshots(pattern); -2892 for (final SnapshotDescription snapshot : snapshots) { -2893 try { -2894 internalDeleteSnapshot(snapshot); -2895 } catch (IOException ex) { -2896 LOG.info( -2897 "Failed to delete snapshot " + snapshot.getName() + " for table " + snapshot.getTableNameAsString(), -2898 ex); -2899 } -2900 } -2901 } -2902 -2903 private void internalDeleteSnapshot(final SnapshotDescription snapshot) throws IOException { -2904 executeCallable(new MasterCallable<Void>(getConnection(), getRpcControllerFactory()) { -2905 @Override -2906 protected Void rpcCall() throws Exception { -2907 this.master.deleteSnapshot(getRpcController(), DeleteSnapshotRequest.newBuilder() -2908 .setSnapshot(ProtobufUtil.createHBaseProtosSnapshotDesc(snapshot)).build()); -2909 return null; -2910 } -2911 }); -2912 } -2913 -2914 @Override -2915 public void deleteTableSnapshots(String tableNameRegex, String snapshotNameRegex) -2916 throws IOException { -2917 deleteTableSnapshots(Pattern.compile(tableNameRegex), Pattern.compile(snapshotNameRegex)); -2918 } -2919 -2920 @Override -2921 public void deleteTableSnapshots(Pattern tableNamePattern, Pattern snapshotNamePattern) -2922 throws IOException { -2923 List<SnapshotDescription> snapshots = listTableSnapshots(tableNamePattern, snapshotNamePattern); -2924 for (SnapshotDescription snapshot : snapshots) { -2925 try { -2926 internalDeleteSnapshot(snapshot); -2927 LOG.debug("Successfully deleted snapshot: " + snapshot.getName()); -2928 } catch (IOException e) { -2929 LOG.error("Failed to delete snapshot: " + snapshot.getName(), e); -2930 } -2931 } -2932 } -2933 -2934 @Override -2935 public void setQuota(final QuotaSettings quota) throws IOException { -2936 executeCallable(new MasterCallable<Void>(getConnection(), getRpcControllerFactory()) { -2937 @Override -2938 protected Void rpcCall() throws Exception { -2939 this.master.setQuota(getRpcController(), QuotaSettings.buildSetQuotaRequestProto(quota)); -2940 return null; -2941 } -2942 }); -2943 } -2944 -2945 @Override -2946 public QuotaRetriever getQuotaRetriever(final QuotaFilter filter) throws IOException { -2947 return QuotaRetriever.open(conf, filter); -2948 } -2949 -2950 private <C extends RetryingCallable<V> & Closeable, V> V executeCallable(C callable) -2951 throws IOException { -2952 return executeCallable(callable, rpcCallerFactory, operationTimeout, rpcTimeout); -2953 } -2954 -2955 static private <C extends RetryingCallable<V> & Closeable, V> V executeCallable(C callable, -2956 RpcRetryingCallerFactory rpcCallerFactory, int operationTimeout, int rpcTimeout) -2957 throws IOException { -2958 RpcRetryingCaller<V> caller = rpcCallerFactory.newCaller(rpcTimeout); -2959 try { -2960 return caller.callWithRetries(callable, operationTimeout); -2961 } finally { -2962 callable.close(); -2963 } -2964 } -2965 -2966 @Override -2967 // Coprocessor Endpoint against the Master. -2968 public CoprocessorRpcChannel coprocessorService() { -2969 return new SyncCoprocessorRpcChannel() { -2970 @Override -2971 protected Message callExecService(final RpcController controller, -2972 final Descriptors.MethodDescriptor method, final Message request, -2973 final Message responsePrototype) -2974 throws IOException { -2975 if (LOG.isTraceEnabled()) { -2976 LOG.trace("Call: " + method.getName() + ", " + request.toString()); -2977 } -2978 // Try-with-resources so close gets called when we are done. -2979 try (MasterCallable<CoprocessorServiceResponse> callable = -2980 new MasterCallable<CoprocessorServiceResponse>(connection, -2981 connection.getRpcControllerFactory()) { -2982 @Override -2983 protected CoprocessorServiceResponse rpcCall() throws Exception { -2984 CoprocessorServiceRequest csr = -2985 CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request); -2986 return this.master.execMasterService(getRpcController(), csr); -2987 } -2988 };) { -2989 // TODO: Are we retrying here? Does not seem so. We should use RetryingRpcCaller -2990 callable.prepare(false); -2991 int operationTimeout = connection.getConnectionConfiguration().getOperationTimeout(); -2992 CoprocessorServiceResponse result = callable.call(operationTimeout); -2993 return CoprocessorRpcUtils.getResponse(result, responsePrototype); -2994 } -2995 } -2996 }; -2997 } -2998 -2999 /** -3000 * Simple {@link Abortable}, throwing RuntimeException on abort. -3001 */ -3002 private static class ThrowableAbortable implements Abortable { -3003 @Override -3004 public void abort(String why, Throwable e) { -3005 throw new RuntimeException(why, e); -3006 } -3007 -3008 @Override -3009 public boolean isAborted() { -3010 return true; -3011 } -3012 } -3013 -3014 @Override -3015 public CoprocessorRpcChannel coprocessorService(final ServerName serverName) { -3016 return new SyncCoprocessorRpcChannel() { -3017 @Override -3018 protected Message callExecService(RpcController controller, -3019 Descriptors.MethodDescriptor method, Message request, Message responsePrototype) -3020 throws IOException { -3021 if (LOG.isTraceEnabled()) { -3022 LOG.trace("Call: " + method.getName() + ", " + request.toString()); -3023 } -3024 CoprocessorServiceRequest csr = -3025 CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request); -3026 // TODO: Are we retrying here? Does not seem so. We should use RetryingRpcCaller -3027 // TODO: Make this same as RegionCoprocessorRpcChannel and MasterCoprocessorRpcChannel. They -3028 // are all different though should do same thing; e.g. RpcChannel setup. -3029 ClientProtos.ClientService.BlockingInterface stub = connection.getClient(serverName); -3030 CoprocessorServiceResponse result; -3031 try { -3032 result = stub. -3033 execRegionServerService(connection.getRpcControllerFactory().newController(), csr); -3034 return CoprocessorRpcUtils.getResponse(result, responsePrototype); -3035 } catch (ServiceException e) { -3036 throw ProtobufUtil.handleRemoteException(e); -3037 } -3038 } -3039 }; -3040 } -3041 -3042 @Override -3043 public void updateConfiguration(final ServerName server) throws IOException { -3044 final AdminService.BlockingInterface admin = this.connection.getAdmin(server); -3045 Callable<Void> callable = new Callable<Void>() { -3046 @Override -3047 public Void call() throws Exception { -3048 admin.updateConfiguration(null, UpdateConfigurationRequest.getDefaultInstance()); -3049 return null; -3050 } -3051 }; -3052 ProtobufUtil.call(callable); -3053 } -3054 -3055 @Override -3056 public void updateConfiguration() throws IOException { -3057 for (ServerName server : this.getClusterStatus().getServers()) { -3058 updateConfiguration(server); -3059 } +2789 @Override +2790 public String getOperationType() { +2791 return "MODIFY"; +2792 } +2793 } +2794 +2795 @Override +2796 public List<SnapshotDescription> listSnapshots() throws IOException { +2797 return executeCallable(new MasterCallable<List<SnapshotDescription>>(getConnection(), +2798 getRpcControllerFactory()) { +2799 @Override +2800 protected List<SnapshotDescription> rpcCall() throws Exception { +2801 List<HBaseProtos.SnapshotDescription> snapshotsList = master +2802 .getCompletedSnapshots(getRpcController(), +2803 GetCompletedSnapshotsRequest.newBuilder().build()) +2804 .getSnapshotsList(); +2805 List<SnapshotDescription> result = new ArrayList<>(snapshotsList.size()); +2806 for (HBaseProtos.SnapshotDescription snapshot : snapshotsList) { +2807 result.add(ProtobufUtil.createSnapshotDesc(snapshot)); +2808 } +2809 return result; +2810 } +2811 }); +2812 } +2813 +2814 @Override +2815 public List<SnapshotDescription> listSnapshots(String regex) throws IOException { +2816 return listSnapshots(Pattern.compile(regex)); +2817 } +2818 +2819 @Override +2820 public List<SnapshotDescription> listSnapshots(Pattern pattern) throws IOException { +2821 List<SnapshotDescription> matched = new LinkedList<>(); +2822 List<SnapshotDescription> snapshots = listSnapshots(); +2823 for (SnapshotDescription snapshot : snapshots) { +2824 if (pattern.matcher(snapshot.getName()).matches()) { +2825 matched.add(snapshot); +2826 } +2827 } +2828 return matched; +2829 } +2830 +2831 @Override +2832 public List<SnapshotDescription> listTableSnapshots(String tableNameRegex, +2833 String snapshotNameRegex) throws IOException { +2834 return listTableSnapshots(Pattern.compile(tableNameRegex), Pattern.compile(snapshotNameRegex)); +2835 } +2836 +2837 @Override +2838 public List<SnapshotDescription> listTableSnapshots(Pattern tableNamePattern, +2839 Pattern snapshotNamePattern) throws IOException { +2840 TableName[] tableNames = listTableNames(tableNamePattern); +2841 +2842 List<SnapshotDescription> tableSnapshots = new LinkedList<>(); +2843 List<SnapshotDescription> snapshots = listSnapshots(snapshotNamePattern); +2844 +2845 List<TableName> listOfTableNames = Arrays.asList(tableNames); +2846 for (SnapshotDescription snapshot : snapshots) { +2847 if (listOfTableNames.contains(snapshot.getTableName())) { +2848 tableSnapshots.add(snapshot); +2849 } +2850 } +2851 return tableSnapshots; +2852 } +2853 +2854 @Override +2855 public void deleteSnapshot(final byte[] snapshotName) throws IOException { +2856 deleteSnapshot(Bytes.toString(snapshotName)); +2857 } +2858 +2859 @Override +2860 public void deleteSnapshot(final String snapshotName) throws IOException { +2861 // make sure the snapshot is possibly valid +2862 TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(snapshotName)); +2863 // do the delete +2864 executeCallable(new MasterCallable<Void>(getConnection(), getRpcControllerFactory()) { +2865 @Override +2866 protected Void rpcCall() throws Exception { +2867 master.deleteSnapshot(getRpcController(), +2868 DeleteSnapshotRequest.newBuilder().setSnapshot( +2869 HBaseProtos.SnapshotDescription.newBuilder().setName(snapshotName).build()) +2870 .build() +2871 ); +2872 return null; +2873 } +2874 }); +2875 } +2876 +2877 @Override +2878 public void deleteSnapshots(final String regex) throws IOException { +2879 deleteSnapshots(Pattern.compile(regex)); +2880 } +2881 +2882 @Override +2883 public void deleteSnapshots(final Pattern pattern) throws IOException { +2884 List<SnapshotDescription> snapshots = listSnapshots(pattern); +2885 for (final SnapshotDescription snapshot : snapshots) { +2886 try { +2887 internalDeleteSnapshot(snapshot); +2888 } catch (IOException ex) { +2889 LOG.info( +2890 "Failed to delete snapshot " + snapshot.getName() + " for table " + snapshot.getTableNameAsString(), +2891 ex); +2892 } +2893 } +2894 } +2895 +2896 private void internalDeleteSnapshot(final SnapshotDescription snapshot) throws IOException { +2897 executeCallable(new MasterCallable<Void>(getConnection(), getRpcControllerFactory()) { +2898 @Override +2899 protected Void rpcCall() throws Exception { +2900 this.master.deleteSnapshot(getRpcController(), DeleteSnapshotRequest.newBuilder() +2901 .setSnapshot(ProtobufUtil.createHBaseProtosSnapshotDesc(snapshot)).build()); +2902 return null; +2903 } +2904 }); +2905 } +2906 +2907 @Override +2908 public void deleteTableSnapshots(String tableNameRegex, String snapshotNameRegex) +2909 throws IOException { +2910 deleteTableSnapshots(Pattern.compile(tableNameRegex), Pattern.compile(snapshotNameRegex)); +2911 } +2912 +2913 @Override +2914 public void deleteTableSnapshots(Pattern tableNamePattern, Pattern snapshotNamePattern) +2915 throws IOException { +2916 List<SnapshotDescription> snapshots = listTableSnapshots(tableNamePattern, snapshotNamePattern); +2917 for (SnapshotDescription snapshot : snapshots) { +2918 try { +2919 internalDeleteSnapshot(snapshot); +2920 LOG.debug("Successfully deleted snapshot: " + snapshot.getName()); +2921 } catch (IOException e) { +2922 LOG.error("Failed to delete snapshot: " + snapshot.getName(), e); +2923 } +2924 } +2925 } +2926 +2927 @Override +2928 public void setQuota(final QuotaSettings quota) throws IOException { +2929 executeCallable(new MasterCallable<Void>(getConnection(), getRpcControllerFactory()) { +2930 @Override +2931 protected Void rpcCall() throws Exception { +2932 this.master.setQuota(getRpcController(), QuotaSettings.buildSetQuotaRequestProto(quota)); +2933 return null; +2934 } +2935 }); +2936 } +2937 +2938 @Override +2939 public QuotaRetriever getQuotaRetriever(final QuotaFilter filter) throws IOException { +2940 return QuotaRetriever.open(conf, filter); +2941 } +2942 +2943 private <C extends RetryingCallable<V> & Closeable, V> V executeCallable(C callable) +2944 throws IOException { +2945 return executeCallable(callable, rpcCallerFactory, operationTimeout, rpcTimeout); +2946 } +2947 +2948 static private <C extends RetryingCallable<V> & Closeable, V> V executeCallable(C callable, +2949 RpcRetryingCallerFactory rpcCallerFactory, int operationTimeout, int rpcTimeout) +2950 throws IOException { +2951 RpcRetryingCaller<V> caller = rpcCallerFactory.newCaller(rpcTimeout); +2952 try { +2953 return caller.callWithRetries(callable, operationTimeout); +2954 } finally { +2955 callable.close(); +2956 } +2957 } +2958 +2959 @Override +2960 // Coprocessor Endpoint against the Master. +2961 public CoprocessorRpcChannel coprocessorService() { +2962 return new SyncCoprocessorRpcChannel() { +2963 @Override +2964 protected Message callExecService(final RpcController controller, +2965 final Descriptors.MethodDescriptor method, final Message request, +2966 final Message responsePrototype) +2967 throws IOException { +2968 if (LOG.isTraceEnabled()) { +2969 LOG.trace("Call: " + method.getName() + ", " + request.toString()); +2970 } +2971 // Try-with-resources so close gets called when we are done. +2972 try (MasterCallable<CoprocessorServiceResponse> callable = +2973 new MasterCallable<CoprocessorServiceResponse>(connection, +2974 connection.getRpcControllerFactory()) { +2975 @Override +2976 protected CoprocessorServiceResponse rpcCall() throws Exception { +2977 CoprocessorServiceRequest csr = +2978 CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request); +2979 return this.master.execMasterService(getRpcController(), csr); +2980 } +2981 };) { +2982 // TODO: Are we retrying here? Does not seem so. We should use RetryingRpcCaller +2983 callable.prepare(false); +2984 int operationTimeout = connection.getConnectionConfiguration().getOperationTimeout(); +2985 CoprocessorServiceResponse result = callable.call(operationTimeout); +2986 return CoprocessorRpcUtils.getResponse(result, responsePrototype); +2987 } +2988 } +2989 }; +2990 } +2991 +2992 /** +2993 * Simple {@link Abortable}, throwing RuntimeException on abort. +2994 */ +2995 private static class ThrowableAbortable implements Abortable { +2996 @Override +2997 public void abort(String why, Throwable e) { +2998 throw new RuntimeException(why, e); +2999 } +3000 +3001 @Override +3002 public boolean isAborted() { +3003 return true; +3004 } +3005 } +3006 +3007 @Override +3008 public CoprocessorRpcChannel coprocessorService(final ServerName serverName) { +3009 return new SyncCoprocessorRpcChannel() { +3010 @Override +3011 protected Message callExecService(RpcController controller, +3012 Descriptors.MethodDescriptor method, Message request, Message responsePrototype) +3013 throws IOException { +3014 if (LOG.isTraceEnabled()) { +3015 LOG.trace("Call: " + method.getName() + ", " + request.toString()); +3016 } +3017 CoprocessorServiceRequest csr = +3018 CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request); +3019 // TODO: Are we retrying here? Does not seem so. We should use RetryingRpcCaller +3020 // TODO: Make this same as RegionCoprocessorRpcChannel and MasterCoprocessorRpcChannel. They +3021 // are all different though should do same thing; e.g. RpcChannel setup. +3022 ClientProtos.ClientService.BlockingInterface stub = connection.getClient(serverName); +3023 CoprocessorServiceResponse result; +3024 try { +3025 result = stub. +3026 execRegionServerService(connection.getRpcControllerFactory().newController(), csr); +3027 return CoprocessorRpcUtils.getResponse(result, responsePrototype); +3028 } catch (ServiceException e) { +3029 throw ProtobufUtil.handleRemoteException(e); +3030 } +3031 } +3032 }; +3033 } +3034 +3035 @Override +3036 public void updateConfiguration(final ServerName server) throws IOException { +3037 final AdminService.BlockingInterface admin = this.connection.getAdmin(server); +3038 Callable<Void> callable = new Callable<Void>() { +3039 @Override +3040 public Void call() throws Exception { +3041 admin.updateConfiguration(null, UpdateConfigurationRequest.getDefaultInstance()); +3042 return null; +3043 } +3044 }; +3045 ProtobufUtil.call(callable); +3046 } +3047 +3048 @Override +3049 public void updateConfiguration() throws IOException { +3050 for (ServerName server : this.getClusterStatus().getServers()) { +3051 updateConfiguration(server); +3052 } +3053 +3054 updateConfiguration(this.getClusterStatus().getMaster()); +3055 +3056 for (ServerName server : this.getClusterStatus().getBackupMasters()) { +3057 updateConfiguration(server); +3058 } +3059 } 3060 -3061 updateConfiguration(this.getClusterStatus().getMaster()); -3062 -3063 for