@@ -47,16 +47,15 @@ public class ContainerReportHandler extends AbstractContainerReportHandler
47
47
private static final Logger LOG =
48
48
LoggerFactory .getLogger (ContainerReportHandler .class );
49
49
50
- private final NodeManager nodeManager ;
51
- private final ContainerManager containerManager ;
52
- private final String unknownContainerHandleAction ;
50
+ enum UnknownContainerAction {
51
+ WARN , DELETE ;
53
52
54
- /**
55
- * The action taken by ContainerReportHandler to handle
56
- * unknown containers.
57
- */
58
- static final String UNKNOWN_CONTAINER_ACTION_WARN = "WARN" ;
59
- static final String UNKNOWN_CONTAINER_ACTION_DELETE = "DELETE" ;
53
+ static UnknownContainerAction parse ( String s ) {
54
+ return s . equals ( DELETE . name ()) ? DELETE : WARN ;
55
+ }
56
+ }
57
+
58
+ private final UnknownContainerAction unknownContainerHandleAction ;
60
59
61
60
/**
62
61
* Constructs ContainerReportHandler instance with the
@@ -70,18 +69,21 @@ public ContainerReportHandler(final NodeManager nodeManager,
70
69
final ContainerManager containerManager ,
71
70
final SCMContext scmContext ,
72
71
OzoneConfiguration conf ) {
73
- super (containerManager , scmContext , LOG );
74
- this .nodeManager = nodeManager ;
75
- this .containerManager = containerManager ;
72
+ super (nodeManager , containerManager , scmContext );
76
73
77
74
if (conf != null ) {
78
75
ScmConfig scmConfig = conf .getObject (ScmConfig .class );
79
- unknownContainerHandleAction = scmConfig .getUnknownContainerAction ();
76
+ unknownContainerHandleAction = UnknownContainerAction . parse ( scmConfig .getUnknownContainerAction () );
80
77
} else {
81
- unknownContainerHandleAction = UNKNOWN_CONTAINER_ACTION_WARN ;
78
+ unknownContainerHandleAction = UnknownContainerAction . WARN ;
82
79
}
83
80
}
84
81
82
+ @ Override
83
+ protected Logger getLogger () {
84
+ return LOG ;
85
+ }
86
+
85
87
public ContainerReportHandler (final NodeManager nodeManager ,
86
88
final ContainerManager containerManager ) {
87
89
this (nodeManager , containerManager , SCMContext .emptyContext (), null );
@@ -142,10 +144,9 @@ public void onMessage(final ContainerReportFromDatanode reportFromDatanode,
142
144
143
145
final DatanodeDetails dnFromReport =
144
146
reportFromDatanode .getDatanodeDetails ();
145
- final DatanodeDetails datanodeDetails = nodeManager .getNode (dnFromReport .getID ());
147
+ final DatanodeDetails datanodeDetails = getNodeManager () .getNode (dnFromReport .getID ());
146
148
if (datanodeDetails == null ) {
147
- LOG .warn ("Received container report from unknown datanode {}" ,
148
- dnFromReport );
149
+ getLogger ().warn ("Datanode not found: {}" , dnFromReport );
149
150
return ;
150
151
}
151
152
final ContainerReportsProto containerReport =
@@ -159,7 +160,7 @@ public void onMessage(final ContainerReportFromDatanode reportFromDatanode,
159
160
final List <ContainerReplicaProto > replicas =
160
161
containerReport .getReportsList ();
161
162
final Set <ContainerID > expectedContainersInDatanode =
162
- nodeManager .getContainers (datanodeDetails );
163
+ getNodeManager () .getContainers (datanodeDetails );
163
164
164
165
for (ContainerReplicaProto replica : replicas ) {
165
166
ContainerID cid = ContainerID .valueOf (replica .getContainerID ());
@@ -169,7 +170,7 @@ public void onMessage(final ContainerReportFromDatanode reportFromDatanode,
169
170
// from protobuf. However we don't want to store that object if
170
171
// there is already an instance for the same ContainerID we can
171
172
// reuse.
172
- container = containerManager .getContainer (cid );
173
+ container = getContainerManager () .getContainer (cid );
173
174
cid = container .containerID ();
174
175
} catch (ContainerNotFoundException e ) {
175
176
// Ignore this for now. It will be handled later with a null check
@@ -181,7 +182,7 @@ public void onMessage(final ContainerReportFromDatanode reportFromDatanode,
181
182
boolean alreadyInDn = expectedContainersInDatanode .remove (cid );
182
183
if (!alreadyInDn ) {
183
184
// This is a new Container not in the nodeManager -> dn map yet
184
- nodeManager .addContainer (datanodeDetails , cid );
185
+ getNodeManager () .addContainer (datanodeDetails , cid );
185
186
}
186
187
if (container == null || ContainerReportValidator
187
188
.validate (container , datanodeDetails , replica )) {
@@ -193,17 +194,16 @@ public void onMessage(final ContainerReportFromDatanode reportFromDatanode,
193
194
// report, so it is now missing on the DN. We need to remove it from the
194
195
// list
195
196
processMissingReplicas (datanodeDetails , expectedContainersInDatanode );
196
- containerManager .notifyContainerReportProcessing (true , true );
197
+ getContainerManager () .notifyContainerReportProcessing (true , true );
197
198
if (reportFromDatanode .isRegister ()) {
198
199
publisher .fireEvent (SCMEvents .CONTAINER_REGISTRATION_REPORT ,
199
200
new SCMDatanodeProtocolServer .NodeRegistrationContainerReport (datanodeDetails ,
200
201
reportFromDatanode .getReport ()));
201
202
}
202
203
}
203
204
} catch (NodeNotFoundException ex ) {
204
- containerManager .notifyContainerReportProcessing (true , false );
205
- LOG .error ("Received container report from unknown datanode {}." ,
206
- datanodeDetails , ex );
205
+ getContainerManager ().notifyContainerReportProcessing (true , false );
206
+ getLogger ().warn ("Datanode not found: {}" , datanodeDetails , ex );
207
207
}
208
208
209
209
}
@@ -224,11 +224,9 @@ private void processSingleReplica(final DatanodeDetails datanodeDetails,
224
224
final EventPublisher publisher ) {
225
225
final Object detailsForLogging = getDetailsForLogging (container , replicaProto , datanodeDetails );
226
226
if (container == null ) {
227
- if (unknownContainerHandleAction .equals (
228
- UNKNOWN_CONTAINER_ACTION_WARN )) {
227
+ if (unknownContainerHandleAction == UnknownContainerAction .WARN ) {
229
228
getLogger ().error ("CONTAINER_NOT_FOUND for {}" , detailsForLogging );
230
- } else if (unknownContainerHandleAction .equals (
231
- UNKNOWN_CONTAINER_ACTION_DELETE )) {
229
+ } else if (unknownContainerHandleAction == UnknownContainerAction .DELETE ) {
232
230
final ContainerID containerId = ContainerID
233
231
.valueOf (replicaProto .getContainerID ());
234
232
deleteReplica (containerId , datanodeDetails , publisher , "CONTAINER_NOT_FOUND" , true , detailsForLogging );
@@ -253,26 +251,26 @@ private void processMissingReplicas(final DatanodeDetails datanodeDetails,
253
251
final Set <ContainerID > missingReplicas ) {
254
252
for (ContainerID id : missingReplicas ) {
255
253
try {
256
- nodeManager .removeContainer (datanodeDetails , id );
254
+ getNodeManager () .removeContainer (datanodeDetails , id );
257
255
} catch (NodeNotFoundException e ) {
258
- LOG .warn ("Failed to remove container {} from a node which does not " +
259
- "exist {}" , id , datanodeDetails , e );
256
+ getLogger () .warn ("Failed to remove missing container {}: datanode {} not found" ,
257
+ id , datanodeDetails , e );
260
258
}
261
259
try {
262
- containerManager .getContainerReplicas (id ).stream ()
260
+ getContainerManager () .getContainerReplicas (id ).stream ()
263
261
.filter (replica -> replica .getDatanodeDetails ()
264
262
.equals (datanodeDetails )).findFirst ()
265
263
.ifPresent (replica -> {
266
264
try {
267
- containerManager .removeContainerReplica (id , replica );
265
+ getContainerManager () .removeContainerReplica (id , replica );
268
266
} catch (ContainerNotFoundException |
269
267
ContainerReplicaNotFoundException ignored ) {
270
268
// This should not happen, but even if it happens, not an issue
271
269
}
272
270
});
273
271
} catch (ContainerNotFoundException e ) {
274
- LOG .warn ("Cannot remove container replica, container {} not found. " ,
275
- id , e );
272
+ getLogger () .warn ("Failed to remove container replica: container {} not found in datanode {} " ,
273
+ id , datanodeDetails , e );
276
274
}
277
275
}
278
276
}
0 commit comments