22
22
import java .util .ArrayList ;
23
23
import java .util .Collections ;
24
24
import java .util .List ;
25
+ import java .util .Optional ;
25
26
import java .util .stream .Collectors ;
27
+ import org .apache .hadoop .conf .Configuration ;
26
28
import org .apache .hadoop .hbase .HRegionLocation ;
27
29
import org .apache .hadoop .hbase .TableName ;
30
+ import org .apache .hadoop .hbase .client .TableDescriptor ;
28
31
import org .apache .hadoop .hbase .conf .ConfigKey ;
29
32
import org .apache .hadoop .hbase .master .assignment .RegionStateNode ;
30
33
import org .apache .hadoop .hbase .master .assignment .TransitRegionStateProcedure ;
@@ -83,6 +86,23 @@ public class ReopenTableRegionsProcedure
83
86
private long regionsReopened = 0 ;
84
87
private long batchesProcessed = 0 ;
85
88
89
+ /**
90
+ * Create a new ReopenTableRegionsProcedure respecting the throttling configuration for the table.
91
+ * First check the table descriptor, then fall back to the global configuration. Only used in
92
+ * ModifyTableProcedure.
93
+ */
94
+ public static ReopenTableRegionsProcedure throttled (final Configuration conf ,
95
+ final TableDescriptor desc ) {
96
+ long backoffMillis = Optional .ofNullable (desc .getValue (PROGRESSIVE_BATCH_BACKOFF_MILLIS_KEY ))
97
+ .map (Long ::parseLong ).orElseGet (() -> conf .getLong (PROGRESSIVE_BATCH_BACKOFF_MILLIS_KEY ,
98
+ PROGRESSIVE_BATCH_BACKOFF_MILLIS_DEFAULT ));
99
+ int batchSizeMax = Optional .ofNullable (desc .getValue (PROGRESSIVE_BATCH_SIZE_MAX_KEY ))
100
+ .map (Integer ::parseInt ).orElseGet (
101
+ () -> conf .getInt (PROGRESSIVE_BATCH_SIZE_MAX_KEY , PROGRESSIVE_BATCH_SIZE_MAX_DISABLED ));
102
+
103
+ return new ReopenTableRegionsProcedure (desc .getTableName (), backoffMillis , batchSizeMax );
104
+ }
105
+
86
106
public ReopenTableRegionsProcedure () {
87
107
this (null );
88
108
}
@@ -96,12 +116,14 @@ public ReopenTableRegionsProcedure(final TableName tableName, final List<byte[]>
96
116
PROGRESSIVE_BATCH_SIZE_MAX_DISABLED );
97
117
}
98
118
99
- public ReopenTableRegionsProcedure (final TableName tableName , long reopenBatchBackoffMillis ,
119
+ @ RestrictedApi (explanation = "Should only be called in tests" , link = "" ,
120
+ allowedOnPath = ".*/src/test/.*" )
121
+ ReopenTableRegionsProcedure (final TableName tableName , long reopenBatchBackoffMillis ,
100
122
int reopenBatchSizeMax ) {
101
123
this (tableName , Collections .emptyList (), reopenBatchBackoffMillis , reopenBatchSizeMax );
102
124
}
103
125
104
- public ReopenTableRegionsProcedure (final TableName tableName , final List <byte []> regionNames ,
126
+ private ReopenTableRegionsProcedure (final TableName tableName , final List <byte []> regionNames ,
105
127
long reopenBatchBackoffMillis , int reopenBatchSizeMax ) {
106
128
this .tableName = tableName ;
107
129
this .regionNames = regionNames ;
@@ -137,6 +159,12 @@ public long getBatchesProcessed() {
137
159
return batchesProcessed ;
138
160
}
139
161
162
+ @ RestrictedApi (explanation = "Should only be called in tests" , link = "" ,
163
+ allowedOnPath = ".*/src/test/.*" )
164
+ long getReopenBatchBackoffMillis () {
165
+ return reopenBatchBackoffMillis ;
166
+ }
167
+
140
168
@ RestrictedApi (explanation = "Should only be called internally or in tests" , link = "" ,
141
169
allowedOnPath = ".*(/src/test/.*|ReopenTableRegionsProcedure).java" )
142
170
protected int progressBatchSize () {
0 commit comments