Skip to content

Commit ff56ce6

Browse files
committed
Add ContainerStateManagerInvoker
1 parent faf4dfc commit ff56ce6

4 files changed

Lines changed: 522 additions & 32 deletions

File tree

hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerStateManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
2929
import org.apache.hadoop.hdds.protocol.proto.SCMRatisProtocol.RequestType;
3030
import org.apache.hadoop.hdds.scm.ha.SCMHandler;
31+
import org.apache.hadoop.hdds.scm.ha.invoker.ScmInvokerCodeGenerator;
3132
import org.apache.hadoop.hdds.scm.metadata.Replicate;
3233
import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
3334
import org.apache.hadoop.hdds.utils.db.Table;
@@ -236,4 +237,8 @@ default RequestType getType() {
236237
@Replicate
237238
void updateContainerInfo(HddsProtos.ContainerInfoProto containerInfo)
238239
throws IOException;
240+
241+
static void main(String[] args) {
242+
ScmInvokerCodeGenerator.generate(ContainerStateManager.class, true);
243+
}
239244
}

hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerStateManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.apache.hadoop.hdds.scm.container.states.ContainerStateMap;
5959
import org.apache.hadoop.hdds.scm.ha.ExecutionUtil;
6060
import org.apache.hadoop.hdds.scm.ha.SCMRatisServer;
61+
import org.apache.hadoop.hdds.scm.ha.invoker.ContainerStateManagerInvoker;
6162
import org.apache.hadoop.hdds.scm.metadata.DBTransactionBuffer;
6263
import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
6364
import org.apache.hadoop.hdds.scm.pipeline.PipelineManager;
@@ -653,7 +654,7 @@ public ContainerStateManager build() throws IOException {
653654
conf, pipelineMgr, table, transactionBuffer,
654655
containerReplicaPendingOps);
655656

656-
return scmRatisServer.getProxyHandler(ContainerStateManager.class, csm);
657+
return scmRatisServer.getProxyHandler(new ContainerStateManagerInvoker(csm, scmRatisServer));
657658
}
658659

659660
}
Lines changed: 328 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,328 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hadoop.hdds.scm.ha.invoker;
19+
20+
import java.io.IOException;
21+
import java.util.List;
22+
import java.util.Map;
23+
import java.util.NavigableSet;
24+
import java.util.Set;
25+
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
26+
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ContainerInfoProto;
27+
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent;
28+
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState;
29+
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
30+
import org.apache.hadoop.hdds.scm.container.ContainerID;
31+
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
32+
import org.apache.hadoop.hdds.scm.container.ContainerReplica;
33+
import org.apache.hadoop.hdds.scm.container.ContainerStateManager;
34+
import org.apache.hadoop.hdds.scm.ha.SCMRatisResponse;
35+
import org.apache.hadoop.hdds.scm.ha.SCMRatisServer;
36+
import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
37+
import org.apache.hadoop.hdds.utils.db.Table;
38+
import org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException;
39+
import org.apache.ratis.protocol.Message;
40+
41+
/** Code generated for {@link ContainerStateManager}. Do not modify. */
42+
public class ContainerStateManagerInvoker extends ScmInvoker<ContainerStateManager> {
43+
enum ReplicateMethod implements NameAndParameterTypes {
44+
addContainer(new Class<?>[][] {
45+
null,
46+
new Class<?>[] {ContainerInfoProto.class}
47+
}),
48+
removeContainer(new Class<?>[][] {
49+
null,
50+
new Class<?>[] {HddsProtos.ContainerID.class}
51+
}),
52+
transitionDeletingOrDeletedToTargetState(new Class<?>[][] {
53+
null,
54+
null,
55+
new Class<?>[] {HddsProtos.ContainerID.class, LifeCycleState.class}
56+
}),
57+
updateContainerInfo(new Class<?>[][] {
58+
null,
59+
new Class<?>[] {ContainerInfoProto.class}
60+
}),
61+
updateContainerStateWithSequenceId(new Class<?>[][] {
62+
null,
63+
null,
64+
null,
65+
new Class<?>[] {HddsProtos.ContainerID.class, LifeCycleEvent.class, Long.class}
66+
});
67+
68+
private final Class<?>[][] parameterTypes;
69+
70+
ReplicateMethod(Class<?>[][] parameterTypes) {
71+
this.parameterTypes = parameterTypes;
72+
}
73+
74+
@Override
75+
public Class<?>[] getParameterTypes(int numArgs) {
76+
return parameterTypes[numArgs];
77+
}
78+
}
79+
80+
public ContainerStateManagerInvoker(ContainerStateManager impl, SCMRatisServer ratis) {
81+
super(impl, ContainerStateManagerInvoker::newProxy, ratis);
82+
}
83+
84+
@Override
85+
public Class<ContainerStateManager> getApi() {
86+
return ContainerStateManager.class;
87+
}
88+
89+
static ContainerStateManager newProxy(ScmInvoker<ContainerStateManager> invoker) {
90+
return new ContainerStateManager() {
91+
92+
@Override
93+
public void addContainer(ContainerInfoProto arg0) throws IOException {
94+
final Object[] args = {arg0};
95+
invoker.invokeReplicateDirect(ReplicateMethod.addContainer, args);
96+
}
97+
98+
@Override
99+
public boolean contains(ContainerID arg0) {
100+
return invoker.getImpl().contains(arg0);
101+
}
102+
103+
@Override
104+
public ContainerInfo getContainer(ContainerID arg0) {
105+
return invoker.getImpl().getContainer(arg0);
106+
}
107+
108+
@Override
109+
public int getContainerCount(LifeCycleState arg0) {
110+
return invoker.getImpl().getContainerCount(arg0);
111+
}
112+
113+
@Override
114+
public List<ContainerID> getContainerIDs(LifeCycleState arg0, ContainerID arg1, int arg2) {
115+
return invoker.getImpl().getContainerIDs(arg0, arg1, arg2);
116+
}
117+
118+
@Override
119+
public List<ContainerInfo> getContainerInfos(ReplicationType arg0) {
120+
return invoker.getImpl().getContainerInfos(arg0);
121+
}
122+
123+
@Override
124+
public List<ContainerInfo> getContainerInfos(LifeCycleState arg0) {
125+
return invoker.getImpl().getContainerInfos(arg0);
126+
}
127+
128+
@Override
129+
public List<ContainerInfo> getContainerInfos(ContainerID arg0, int arg1) {
130+
return invoker.getImpl().getContainerInfos(arg0, arg1);
131+
}
132+
133+
@Override
134+
public List<ContainerInfo> getContainerInfos(LifeCycleState arg0, ContainerID arg1, int arg2) {
135+
return invoker.getImpl().getContainerInfos(arg0, arg1, arg2);
136+
}
137+
138+
@Override
139+
public Set<ContainerReplica> getContainerReplicas(ContainerID arg0) {
140+
return invoker.getImpl().getContainerReplicas(arg0);
141+
}
142+
143+
@Override
144+
public ContainerInfo getMatchingContainer(long arg0, String arg1, PipelineID arg2, NavigableSet arg3) {
145+
return invoker.getImpl().getMatchingContainer(arg0, arg1, arg2, arg3);
146+
}
147+
148+
@Override
149+
public void reinitialize(Table arg0) throws IOException {
150+
invoker.getImpl().reinitialize(arg0);
151+
}
152+
153+
@Override
154+
public void removeContainer(HddsProtos.ContainerID arg0) throws IOException {
155+
final Object[] args = {arg0};
156+
invoker.invokeReplicateDirect(ReplicateMethod.removeContainer, args);
157+
}
158+
159+
@Override
160+
public void removeContainerReplica(ContainerReplica arg0) {
161+
invoker.getImpl().removeContainerReplica(arg0);
162+
}
163+
164+
@Override
165+
public void transitionDeletingOrDeletedToTargetState(HddsProtos.ContainerID arg0, LifeCycleState arg1) throws
166+
IOException {
167+
final Object[] args = {arg0, arg1};
168+
invoker.invokeReplicateDirect(ReplicateMethod.transitionDeletingOrDeletedToTargetState, args);
169+
}
170+
171+
@Override
172+
public void updateContainerInfo(ContainerInfoProto arg0) throws IOException {
173+
final Object[] args = {arg0};
174+
invoker.invokeReplicateDirect(ReplicateMethod.updateContainerInfo, args);
175+
}
176+
177+
@Override
178+
public void updateContainerReplica(ContainerReplica arg0) {
179+
invoker.getImpl().updateContainerReplica(arg0);
180+
}
181+
182+
@Override
183+
public void updateContainerStateWithSequenceId(HddsProtos.ContainerID arg0, LifeCycleEvent arg1, Long arg2) throws
184+
IOException, InvalidStateTransitionException {
185+
final Object[] args = {arg0, arg1, arg2};
186+
invoker.invokeReplicateDirect(ReplicateMethod.updateContainerStateWithSequenceId, args);
187+
}
188+
189+
@Override
190+
public void updateDeleteTransactionId(Map arg0) throws IOException {
191+
invoker.getImpl().updateDeleteTransactionId(arg0);
192+
}
193+
};
194+
}
195+
196+
@SuppressWarnings("unchecked")
197+
@Override
198+
public Message invokeLocal(String methodName, Object[] p) throws Exception {
199+
final Class<?> returnType;
200+
final Object returnValue;
201+
switch (methodName) {
202+
case "addContainer":
203+
final ContainerInfoProto arg0 = p.length > 0 ? (ContainerInfoProto) p[0] : null;
204+
getImpl().addContainer(arg0);
205+
return Message.EMPTY;
206+
207+
case "contains":
208+
final ContainerID arg1 = p.length > 0 ? (ContainerID) p[0] : null;
209+
returnType = boolean.class;
210+
returnValue = getImpl().contains(arg1);
211+
break;
212+
213+
case "getContainer":
214+
final ContainerID arg2 = p.length > 0 ? (ContainerID) p[0] : null;
215+
returnType = ContainerInfo.class;
216+
returnValue = getImpl().getContainer(arg2);
217+
break;
218+
219+
case "getContainerCount":
220+
final LifeCycleState arg3 = p.length > 0 ? (LifeCycleState) p[0] : null;
221+
returnType = int.class;
222+
returnValue = getImpl().getContainerCount(arg3);
223+
break;
224+
225+
case "getContainerIDs":
226+
final LifeCycleState arg4 = p.length > 0 ? (LifeCycleState) p[0] : null;
227+
final ContainerID arg5 = p.length > 1 ? (ContainerID) p[1] : null;
228+
final int arg6 = p.length > 2 ? (int) p[2] : 0;
229+
returnType = List.class;
230+
returnValue = getImpl().getContainerIDs(arg4, arg5, arg6);
231+
break;
232+
233+
case "getContainerInfos":
234+
if (p.length == 1 && (p[0] == null || ReplicationType.class.isInstance(p[0]))) {
235+
final ReplicationType arg7 = (ReplicationType) p[0];
236+
returnType = List.class;
237+
returnValue = getImpl().getContainerInfos(arg7);
238+
break;
239+
}
240+
if (p.length == 1 && (p[0] == null || LifeCycleState.class.isInstance(p[0]))) {
241+
final LifeCycleState arg8 = (LifeCycleState) p[0];
242+
returnType = List.class;
243+
returnValue = getImpl().getContainerInfos(arg8);
244+
break;
245+
}
246+
if (p.length == 2 && (p[0] == null || ContainerID.class.isInstance(p[0])) && p[1] instanceof Integer) {
247+
final ContainerID arg9 = (ContainerID) p[0];
248+
final int arg10 = (int) p[1];
249+
returnType = List.class;
250+
returnValue = getImpl().getContainerInfos(arg9, arg10);
251+
break;
252+
}
253+
if (p.length == 3 && (p[0] == null || LifeCycleState.class.isInstance(p[0])) && (p[1] == null ||
254+
ContainerID.class.isInstance(p[1])) && p[2] instanceof Integer) {
255+
final LifeCycleState arg11 = (LifeCycleState) p[0];
256+
final ContainerID arg12 = (ContainerID) p[1];
257+
final int arg13 = (int) p[2];
258+
returnType = List.class;
259+
returnValue = getImpl().getContainerInfos(arg11, arg12, arg13);
260+
break;
261+
}
262+
throw new IllegalArgumentException("Method not found: " + methodName + " in ContainerStateManager");
263+
264+
case "getContainerReplicas":
265+
final ContainerID arg14 = p.length > 0 ? (ContainerID) p[0] : null;
266+
returnType = Set.class;
267+
returnValue = getImpl().getContainerReplicas(arg14);
268+
break;
269+
270+
case "getMatchingContainer":
271+
final long arg15 = p.length > 0 ? (long) p[0] : 0L;
272+
final String arg16 = p.length > 1 ? (String) p[1] : null;
273+
final PipelineID arg17 = p.length > 2 ? (PipelineID) p[2] : null;
274+
final NavigableSet arg18 = p.length > 3 ? (NavigableSet) p[3] : null;
275+
returnType = ContainerInfo.class;
276+
returnValue = getImpl().getMatchingContainer(arg15, arg16, arg17, arg18);
277+
break;
278+
279+
case "reinitialize":
280+
final Table arg19 = p.length > 0 ? (Table) p[0] : null;
281+
getImpl().reinitialize(arg19);
282+
return Message.EMPTY;
283+
284+
case "removeContainer":
285+
final HddsProtos.ContainerID arg20 = p.length > 0 ? (HddsProtos.ContainerID) p[0] : null;
286+
getImpl().removeContainer(arg20);
287+
return Message.EMPTY;
288+
289+
case "removeContainerReplica":
290+
final ContainerReplica arg21 = p.length > 0 ? (ContainerReplica) p[0] : null;
291+
getImpl().removeContainerReplica(arg21);
292+
return Message.EMPTY;
293+
294+
case "transitionDeletingOrDeletedToTargetState":
295+
final HddsProtos.ContainerID arg22 = p.length > 0 ? (HddsProtos.ContainerID) p[0] : null;
296+
final LifeCycleState arg23 = p.length > 1 ? (LifeCycleState) p[1] : null;
297+
getImpl().transitionDeletingOrDeletedToTargetState(arg22, arg23);
298+
return Message.EMPTY;
299+
300+
case "updateContainerInfo":
301+
final ContainerInfoProto arg24 = p.length > 0 ? (ContainerInfoProto) p[0] : null;
302+
getImpl().updateContainerInfo(arg24);
303+
return Message.EMPTY;
304+
305+
case "updateContainerReplica":
306+
final ContainerReplica arg25 = p.length > 0 ? (ContainerReplica) p[0] : null;
307+
getImpl().updateContainerReplica(arg25);
308+
return Message.EMPTY;
309+
310+
case "updateContainerStateWithSequenceId":
311+
final HddsProtos.ContainerID arg26 = p.length > 0 ? (HddsProtos.ContainerID) p[0] : null;
312+
final LifeCycleEvent arg27 = p.length > 1 ? (LifeCycleEvent) p[1] : null;
313+
final Long arg28 = p.length > 2 ? (Long) p[2] : null;
314+
getImpl().updateContainerStateWithSequenceId(arg26, arg27, arg28);
315+
return Message.EMPTY;
316+
317+
case "updateDeleteTransactionId":
318+
final Map arg29 = p.length > 0 ? (Map) p[0] : null;
319+
getImpl().updateDeleteTransactionId(arg29);
320+
return Message.EMPTY;
321+
322+
default:
323+
throw new IllegalArgumentException("Method not found: " + methodName + " in ContainerStateManager");
324+
}
325+
326+
return SCMRatisResponse.encode(returnValue, returnType);
327+
}
328+
}

0 commit comments

Comments
 (0)