18
18
package org .apache .hadoop .hbase .master .procedure ;
19
19
20
20
import java .io .IOException ;
21
+ import java .util .Objects ;
21
22
import java .util .Optional ;
22
23
import org .apache .hadoop .hbase .TableName ;
23
24
import org .apache .hadoop .hbase .client .TableDescriptor ;
@@ -44,20 +45,21 @@ public abstract class ModifyTableDescriptorProcedure
44
45
45
46
private static final Logger LOG = LoggerFactory .getLogger (ModifyTableDescriptorProcedure .class );
46
47
47
- private TableDescriptor unmodifiedTableDescriptor ;
48
+ private TableName tableName ;
49
+
48
50
private TableDescriptor modifiedTableDescriptor ;
49
51
50
52
protected ModifyTableDescriptorProcedure () {
51
53
}
52
54
53
- protected ModifyTableDescriptorProcedure (MasterProcedureEnv env , TableDescriptor unmodified ) {
55
+ protected ModifyTableDescriptorProcedure (MasterProcedureEnv env , TableName tableName ) {
54
56
super (env );
55
- this .unmodifiedTableDescriptor = unmodified ;
57
+ this .tableName = Objects . requireNonNull ( tableName ) ;
56
58
}
57
59
58
60
@ Override
59
61
public TableName getTableName () {
60
- return unmodifiedTableDescriptor . getTableName () ;
62
+ return tableName ;
61
63
}
62
64
63
65
@ Override
@@ -82,7 +84,12 @@ protected Flow executeFromState(MasterProcedureEnv env, ModifyTableDescriptorSta
82
84
try {
83
85
switch (state ) {
84
86
case MODIFY_TABLE_DESCRIPTOR_PREPARE :
85
- Optional <TableDescriptor > modified = modify (env , unmodifiedTableDescriptor );
87
+ TableDescriptor current = env .getMasterServices ().getTableDescriptors ().get (tableName );
88
+ if (current == null ) {
89
+ LOG .info ("Table {} does not exist, skip modifying" , tableName );
90
+ return Flow .NO_MORE_STATE ;
91
+ }
92
+ Optional <TableDescriptor > modified = modify (env , current );
86
93
if (modified .isPresent ()) {
87
94
modifiedTableDescriptor = modified .get ();
88
95
setNextState (ModifyTableDescriptorState .MODIFY_TABLE_DESCRIPTOR_UPDATE );
@@ -108,6 +115,15 @@ protected Flow executeFromState(MasterProcedureEnv env, ModifyTableDescriptorSta
108
115
return Flow .HAS_MORE_STATE ;
109
116
}
110
117
118
+ @ Override
119
+ protected boolean holdLock (MasterProcedureEnv env ) {
120
+ // here we want to make sure that our modification result will not be overwrite by other MTPs,
121
+ // so we set holdLock to true. Since we do not need to schedule any sub procedures, especially
122
+ // no remote procedures, so it is OK for us a hold the lock all the time, it will not hurt the
123
+ // availability too much.
124
+ return true ;
125
+ }
126
+
111
127
@ Override
112
128
protected void rollbackState (MasterProcedureEnv env , ModifyTableDescriptorState state )
113
129
throws IOException , InterruptedException {
@@ -141,7 +157,7 @@ protected ModifyTableDescriptorState getInitialState() {
141
157
protected void serializeStateData (ProcedureStateSerializer serializer ) throws IOException {
142
158
super .serializeStateData (serializer );
143
159
ModifyTableDescriptorStateData .Builder builder = ModifyTableDescriptorStateData .newBuilder ()
144
- .setUnmodifiedTableSchema (ProtobufUtil .toTableSchema ( unmodifiedTableDescriptor ));
160
+ .setTableName (ProtobufUtil .toProtoTableName ( tableName ));
145
161
if (modifiedTableDescriptor != null ) {
146
162
builder .setModifiedTableSchema (ProtobufUtil .toTableSchema (modifiedTableDescriptor ));
147
163
}
@@ -153,7 +169,7 @@ protected void deserializeStateData(ProcedureStateSerializer serializer) throws
153
169
super .deserializeStateData (serializer );
154
170
ModifyTableDescriptorStateData data =
155
171
serializer .deserialize (ModifyTableDescriptorStateData .class );
156
- unmodifiedTableDescriptor = ProtobufUtil .toTableDescriptor (data .getUnmodifiedTableSchema ());
172
+ tableName = ProtobufUtil .toTableName (data .getTableName ());
157
173
if (data .hasModifiedTableSchema ()) {
158
174
modifiedTableDescriptor = ProtobufUtil .toTableDescriptor (data .getModifiedTableSchema ());
159
175
}
0 commit comments