Project

General

Profile

« Previous | Next » 

Revision 6858

Added by Chris Jones over 12 years ago

After reviewing CNodeService and D1NodeService prompted by Robert comparing the Hazelcast locking with the d1_synchronization locking, I've made a number of changes that will prevent locking problems:

1) Multiple methods contained try/catch blocks that would:
try
lock();
catch
throw();
try
put();
catch
throw();
finally
unlock();

So the lock obtained in the first try catch would never unlock if an exception is thrown. This is fixed by using an outer try/catch/finally block for locking and unlocking to ensure the lock is released.

2) In some cases we need to lock() prior to a get() from the hzSystemMetadata, other times we don't when there's no put() subsequently involved (like getChecksum(), get(), etc.) Remove any locking in those cases.

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
141 141
      
142 142
      SystemMetadata systemMetadata = null;
143 143
      try {
144
          if ( HazelcastService.getInstance().getSystemMetadataMap().containsKey(pid) ) {
145
              lock = HazelcastService.getInstance().getLock(pid.getValue());
146
              lock.lock();
147
              systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
144
          lock = HazelcastService.getInstance().getLock(pid.getValue());
145
          lock.lock();
146

  
147
          try {
148
              if ( HazelcastService.getInstance().getSystemMetadataMap().containsKey(pid) ) {
149
                  systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
150
                  
151
              }
152
            
153

  
154
              // does the request have the most current system metadata?
155
              if ( systemMetadata.getSerialVersion().longValue() != serialVersion ) {
156
                 String msg = "The requested system metadata version number " + 
157
                     serialVersion + " differs from the current version at " +
158
                     systemMetadata.getSerialVersion().longValue() +
159
                     ". Please get the latest copy in order to modify it.";
160
                 throw new InvalidRequest("4883", msg);
161
              }
148 162
              
163
          } catch (Exception e) { // Catch is generic since HZ throws RuntimeException
164
              throw new NotFound("4884", "No record found for: " + pid.getValue());
165
            
149 166
          }
150
        
151

  
152
          // does the request have the most current system metadata?
153
          if ( systemMetadata.getSerialVersion().longValue() != serialVersion ) {
154
             String msg = "The requested system metadata version number " + 
155
                 serialVersion + " differs from the current version at " +
156
                 systemMetadata.getSerialVersion().longValue() +
157
                 ". Please get the latest copy in order to modify it.";
158
             throw new InvalidRequest("4883", msg);
167
          
168
          // set the new policy
169
          systemMetadata.setReplicationPolicy(policy);
170
          
171
          // update the metadata
172
          try {
173
              systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
174
              systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
175
              HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata);
176
            
177
          } catch (Exception e) {
178
              throw new ServiceFailure("4882", e.getMessage());
179
          
159 180
          }
160 181
          
161
      } catch (Exception e) { // Catch is generic since HZ throws RuntimeException
162
        throw new NotFound("4884", "No record found for: " + pid.getValue());
182
    } catch (Exception e) {
183
        throw new ServiceFailure("4882", e.getMessage());
163 184
        
164
      }
165
          
166
      // set the new policy
167
      systemMetadata.setReplicationPolicy(policy);
168
      
169
      // update the metadata
170
      try {
171
        systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
172
        systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
173
        HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata);
185
    } finally {
186
        lock.unlock();
187
        logMetacat.debug("Unlocked identifier " + pid.getValue());
174 188
        
175
      } catch (Exception e) {
176
          throw new ServiceFailure("4882", e.getMessage());
177
      
178
      } finally {
179
          lock.unlock();
180
          logMetacat.debug("Unlocked identifier " + pid.getValue());
181

  
182
          
183
      }
189
    }
184 190
    
185 191
      return true;
186 192
  }
......
220 226
          " is " + status.toString());
221 227
      
222 228
      SystemMetadata systemMetadata = null;
223
      try {      
229

  
230
      try {
224 231
          lock = HazelcastService.getInstance().getLock(pid.getValue());
225 232
          lock.lock();
226
          systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
233
          try {      
234
              systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
227 235

  
228
          if ( systemMetadata == null ) {
229
              logMetacat.debug("systemMetadata is null for " + pid.getValue());
236
              if ( systemMetadata == null ) {
237
                  logMetacat.debug("systemMetadata is null for " + pid.getValue());
238
                  
239
              }
240
              replicas = systemMetadata.getReplicaList();
241
              int count = 0;
230 242
              
231
          }
232
          replicas = systemMetadata.getReplicaList();
233
          int count = 0;
234
          
235
          if ( replicas == null || replicas.size() < 1 ) {
236
              logMetacat.debug("no replicas to evaluate");
237
              throw new InvalidRequest("4730", "There are no replicas to update.");
243
              if ( replicas == null || replicas.size() < 1 ) {
244
                  logMetacat.debug("no replicas to evaluate");
245
                  throw new InvalidRequest("4730", "There are no replicas to update.");
246
                  
247
              }
248

  
249
              // find the target replica index in the replica list
250
              for (Replica replica: replicas) {
251
                  String replicaNodeStr = replica.getReplicaMemberNode().getValue();
252
                  String targetNodeStr = targetNode.getValue();
253
                  logMetacat.debug("Comparing " + replicaNodeStr + " to " + targetNodeStr);
254
                  
255
                  if (replicaNodeStr.equals(targetNodeStr)) {
256
                      replicaEntryIndex = count;
257
                      logMetacat.debug("replica entry index is: " + replicaEntryIndex);
258
                      break;
259
                  }
260
                  count++;
261
                  
262
              }
263

  
264
              // are we allowed to do this? only CNs and target MNs are allowed
265
              CNode cn = D1Client.getCN();
266
              List<Node> nodes = cn.listNodes().getNodeList();
238 267
              
239
          }
268
              // find the node in the node list
269
              for ( Node node : nodes ) {
270
                  
271
                  NodeReference nodeReference = node.getIdentifier();
272
                  logMetacat.debug("In setReplicationStatus(), Node reference is: " + nodeReference.getValue());
273
                  
274
                  // allow target MN certs and CN certs
275
                  if (targetNode.getValue().equals(nodeReference.getValue()) ||
276
                      node.getType() == NodeType.CN) {
277
                      List<Subject> nodeSubjects = node.getSubjectList();
278
                      
279
                      // check if the session subject is in the node subject list
280
                      for (Subject nodeSubject : nodeSubjects) {
281
                          if ( nodeSubject.equals(subject) ) {
282
                              allowed = true; // subject of session == target node subject
283
                              break;
284
                              
285
                          }
286
                      }                 
287
                  }
288
              }
240 289

  
241
          // find the target replica index in the replica list
242
          for (Replica replica: replicas) {
243
              String replicaNodeStr = replica.getReplicaMemberNode().getValue();
244
              String targetNodeStr = targetNode.getValue();
245
              logMetacat.debug("Comparing " + replicaNodeStr + " to " + targetNodeStr);
290
              if ( !allowed ) {
291
                  String msg = "The subject identified by " + subject.getValue() +
292
                    " does not have permission to set the replication status for " +
293
                    "the replica identified by " + targetNode.getValue() + ".";
294
                  logMetacat.info(msg);
295
                  throw new NotAuthorized("4720", msg);
296
                  
297
              }
246 298
              
247
              if (replicaNodeStr.equals(targetNodeStr)) {
248
                  replicaEntryIndex = count;
249
                  logMetacat.debug("replica entry index is: " + replicaEntryIndex);
250
                  break;
299
              // was there a failure? log it
300
              if ( failure != null && status == ReplicationStatus.FAILED ) {
301
                 String msg = "The replication request of the object identified by " + 
302
                     pid.getValue() + " failed.  The error message was " +
303
                     failure.getMessage() + ".";
251 304
              }
252
              count++;
253 305
              
306
          } catch (RuntimeException e) { // Catch is generic since HZ throws RuntimeException
307
            throw new NotFound("4740", "No record found for: " + pid.getValue() +
308
                " : " + e.getMessage());
309
            
254 310
          }
255

  
256
          // are we allowed to do this? only CNs and target MNs are allowed
257
          CNode cn = D1Client.getCN();
258
          List<Node> nodes = cn.listNodes().getNodeList();
259 311
          
260
          // find the node in the node list
261
          for ( Node node : nodes ) {
312
          // set the status for the replica
313
          if ( replicaEntryIndex != -1 ) {
314
              Replica targetReplica = replicas.get(replicaEntryIndex);
315
              targetReplica.setReplicationStatus(status);
316
              logMetacat.debug("Set the replication status for " + 
317
                  targetReplica.getReplicaMemberNode().getValue() + " to " +
318
                  targetReplica.getReplicationStatus());
262 319
              
263
              NodeReference nodeReference = node.getIdentifier();
264
              logMetacat.debug("In setReplicationStatus(), Node reference is: " + nodeReference.getValue());
265
              
266
              // allow target MN certs and CN certs
267
              if (targetNode.getValue().equals(nodeReference.getValue()) ||
268
                  node.getType() == NodeType.CN) {
269
                  List<Subject> nodeSubjects = node.getSubjectList();
270
                  
271
                  // check if the session subject is in the node subject list
272
                  for (Subject nodeSubject : nodeSubjects) {
273
                      if ( nodeSubject.equals(subject) ) {
274
                          allowed = true; // subject of session == target node subject
275
                          break;
276
                          
277
                      }
278
                  }                 
279
              }
280
          }
320
          } else {
321
              throw new InvalidRequest("4730", "There are no replicas to update.");
281 322

  
282
          if ( !allowed ) {
283
              String msg = "The subject identified by " + subject.getValue() +
284
                " does not have permission to set the replication status for " +
285
                "the replica identified by " + targetNode.getValue() + ".";
286
              logMetacat.info(msg);
287
              throw new NotAuthorized("4720", msg);
288
              
289 323
          }
290 324
          
291
          // was there a failure? log it
292
          if ( failure != null && status == ReplicationStatus.FAILED ) {
293
             String msg = "The replication request of the object identified by " + 
294
                 pid.getValue() + " failed.  The error message was " +
295
                 failure.getMessage() + ".";
325
          systemMetadata.setReplicaList(replicas);
326
                
327
          // update the metadata
328
          try {
329
              systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
330
              systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
331
              HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata);
332
              
333
              if ( status == ReplicationStatus.FAILED && failure != null ) {
334
                  logMetacat.warn("Replication failed for identifier " + pid.getValue() +
335
                      " on target node " + targetNode + ". The exception was: " +
336
                      failure.getMessage());
337
              }
338
          } catch (Exception e) {
339
              throw new ServiceFailure("4700", e.getMessage());
340
          
296 341
          }
297 342
          
298
      } catch (RuntimeException e) { // Catch is generic since HZ throws RuntimeException
299
        throw new NotFound("4740", "No record found for: " + pid.getValue() +
300
            " : " + e.getMessage());
343
    } catch (Exception e) {
344
        lock.unlock();
345
        logMetacat.debug("Unlocked identifier " + pid.getValue());
301 346
        
302
      }
303
          
304
      // set the status for the replica
305
      if ( replicaEntryIndex != -1 ) {
306
          Replica targetReplica = replicas.get(replicaEntryIndex);
307
          targetReplica.setReplicationStatus(status);
308
          logMetacat.debug("Set the replication status for " + 
309
              targetReplica.getReplicaMemberNode().getValue() + " to " +
310
              targetReplica.getReplicationStatus());
311
          
312
      } else {
313
          throw new InvalidRequest("4730", "There are no replicas to update.");
314

  
315
      }
347
    }
316 348
      
317
      systemMetadata.setReplicaList(replicas);
318
            
319
      // update the metadata
320
      try {
321
          systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
322
          systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
323
          HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata);
324
          
325
          if ( status == ReplicationStatus.FAILED && failure != null ) {
326
              logMetacat.warn("Replication failed for identifier " + pid.getValue() +
327
                  " on target node " + targetNode + ". The exception was: " +
328
                  failure.getMessage());
329
          }
330
      } catch (Exception e) {
331
          throw new ServiceFailure("4700", e.getMessage());
332
      
333
      } finally {
334
          lock.unlock();
335
          logMetacat.debug("Unlocked identifier " + pid.getValue());
336
         
337
      }
338
      
339 349
      return true;
340 350
  }
341 351

  
......
452 462
    Checksum checksum = null;
453 463
    
454 464
    try {
455
        lock = HazelcastService.getInstance().getLock(pid.getValue());
456
        lock.lock();
457 465
        systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
458 466
        checksum = systemMetadata.getChecksum();
459 467

  
......
461 469
        throw new ServiceFailure("1410", "An error occurred getting the checksum for " + 
462 470
            pid.getValue() + ". The error message was: " + e.getMessage());
463 471
      
464
    } finally {
465
        lock.unlock();
466
        logMetacat.debug("Unlocked identifier " + pid.getValue());
467
        
468 472
    }
469 473
    
470 474
    return checksum;
......
819 823
      SystemMetadata systemMetadata = null;
820 824
      try {
821 825
          lock = HazelcastService.getInstance().getLock(pid.getValue());
822
          systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
823 826
          
824
          // does the request have the most current system metadata?
825
          if ( systemMetadata.getSerialVersion().longValue() != serialVersion ) {
826
             String msg = "The requested system metadata version number " + 
827
                 serialVersion + " differs from the current version at " +
828
                 systemMetadata.getSerialVersion().longValue() +
829
                 ". Please get the latest copy in order to modify it.";
830
             throw new InvalidRequest("4442", msg);
827
          try {
828
              systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
829
              
830
              // does the request have the most current system metadata?
831
              if ( systemMetadata.getSerialVersion().longValue() != serialVersion ) {
832
                 String msg = "The requested system metadata version number " + 
833
                     serialVersion + " differs from the current version at " +
834
                     systemMetadata.getSerialVersion().longValue() +
835
                     ". Please get the latest copy in order to modify it.";
836
                 throw new InvalidRequest("4442", msg);
837
              }
838
              
839
          } catch (Exception e) { // Catch is generic since HZ throws RuntimeException
840
              throw new NotFound("4460", "No record found for: " + pid.getValue());
841
              
831 842
          }
843
              
844
          // set the new rights holder
845
          systemMetadata.setRightsHolder(userId);
832 846
          
833
      } catch (Exception e) { // Catch is generic since HZ throws RuntimeException
834
          throw new NotFound("4460", "No record found for: " + pid.getValue());
847
          // update the metadata
848
          try {
849
              systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
850
              systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
851
              HazelcastService.getInstance().getSystemMetadataMap().put(pid, systemMetadata);
852
              
853
          } catch (Exception e) {
854
          throw new ServiceFailure("4490", e.getMessage());
835 855
          
836
      }
856
          }
837 857
          
838
      // set the new rights holder
839
      systemMetadata.setRightsHolder(userId);
840
      
841
      // update the metadata
842
      try {
843
          systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
844
          systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
845
          HazelcastService.getInstance().getSystemMetadataMap().put(pid, systemMetadata);
858
      } catch (Exception e) {
859
          throw new ServiceFailure("4490", e.getMessage());
846 860
          
847
      } catch (Exception e) {
848
      throw new ServiceFailure("4490", e.getMessage());
849
      
850 861
      } finally {
851 862
          lock.unlock();
852 863
          logMetacat.debug("Unlocked identifier " + pid.getValue());
853

  
864
      
854 865
      }
855 866
      
856
      return pid;
867
    return pid;
857 868
  }
858 869

  
859 870
  /**
......
1102 1113
      try {
1103 1114
          lock = HazelcastService.getInstance().getLock(pid.getValue());
1104 1115
          lock.lock();
1105
          systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
1116
          
1117
          try {
1118
              systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
1106 1119

  
1107
          // does the request have the most current system metadata?
1108
          if ( systemMetadata.getSerialVersion().longValue() != serialVersion ) {
1109
             String msg = "The requested system metadata version number " + 
1110
                 serialVersion + " differs from the current version at " +
1111
                 systemMetadata.getSerialVersion().longValue() +
1112
                 ". Please get the latest copy in order to modify it.";
1113
             throw new InvalidRequest("4402", msg);
1120
              // does the request have the most current system metadata?
1121
              if ( systemMetadata.getSerialVersion().longValue() != serialVersion ) {
1122
                 String msg = "The requested system metadata version number " + 
1123
                     serialVersion + " differs from the current version at " +
1124
                     systemMetadata.getSerialVersion().longValue() +
1125
                     ". Please get the latest copy in order to modify it.";
1126
                 throw new InvalidRequest("4402", msg);
1127
              }
1128
              
1129
          } catch (Exception e) {
1130
              // convert Hazelcast RuntimeException to NotFound
1131
              throw new NotFound("4400", "No record found for: " + pid);
1132
            
1114 1133
          }
1134
              
1135
          // set the access policy
1136
          systemMetadata.setAccessPolicy(accessPolicy);
1115 1137
          
1116
      } catch (Exception e) {
1117
          // convert Hazelcast RuntimeException to NotFound
1118
          throw new NotFound("4400", "No record found for: " + pid);
1119
        
1120
      }
1138
          // update the system metadata
1139
          try {
1140
              systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
1141
              systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
1142
              HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata);
1143
            
1144
          } catch (Exception e) {
1145
              // convert Hazelcast RuntimeException to ServiceFailure
1146
              throw new ServiceFailure("4430", e.getMessage());
1147
            
1148
          }
1121 1149
          
1122
      // set the access policy
1123
      systemMetadata.setAccessPolicy(accessPolicy);
1124
      
1125
      // update the system metadata
1126
      try {
1127
          systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
1128
          systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
1129
          HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata);
1130
        
1131 1150
      } catch (Exception e) {
1132
          // convert Hazelcast RuntimeException to ServiceFailure
1133 1151
          throw new ServiceFailure("4430", e.getMessage());
1134
        
1152
          
1135 1153
      } finally {
1136 1154
          lock.unlock();
1137 1155
          logMetacat.debug("Unlocked identifier " + pid.getValue());
1138 1156
        
1139 1157
      }
1158

  
1140 1159
    
1141 1160
    // TODO: how do we know if the map was persisted?
1142 1161
    success = true;
......
1184 1203
      }
1185 1204

  
1186 1205
      SystemMetadata systemMetadata = null;
1187
      try {      
1206
      try {
1188 1207
          lock = HazelcastService.getInstance().getLock(pid.getValue());
1189 1208
          lock.lock();
1190
          systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
1191 1209

  
1192
          // does the request have the most current system metadata?
1193
          if ( systemMetadata.getSerialVersion().longValue() != serialVersion ) {
1194
             String msg = "The requested system metadata version number " + 
1195
                 serialVersion + " differs from the current version at " +
1196
                 systemMetadata.getSerialVersion().longValue() +
1197
                 ". Please get the latest copy in order to modify it.";
1198
             throw new InvalidRequest("4853", msg);
1210
          try {      
1211
              systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
1212

  
1213
              // does the request have the most current system metadata?
1214
              if ( systemMetadata.getSerialVersion().longValue() != serialVersion ) {
1215
                 String msg = "The requested system metadata version number " + 
1216
                     serialVersion + " differs from the current version at " +
1217
                     systemMetadata.getSerialVersion().longValue() +
1218
                     ". Please get the latest copy in order to modify it.";
1219
                 throw new InvalidRequest("4853", msg);
1220
              }
1221
              
1222
          } catch (Exception e) { // Catch is generic since HZ throws RuntimeException
1223
            throw new NotFound("4854", "No record found for: " + pid.getValue() +
1224
                " : " + e.getMessage());
1225
            
1199 1226
          }
1227
              
1228
          // set the status for the replica
1229
          List<Replica> replicas = systemMetadata.getReplicaList();
1230
          NodeReference replicaNode = replica.getReplicaMemberNode();
1231
          int index = 0;
1232
          for (Replica listedReplica: replicas) {
1233
              
1234
              // remove the replica that we are replacing
1235
              if ( replicaNode.getValue().equals(listedReplica.getReplicaMemberNode().getValue())) {
1236
                  replicas.remove(index);
1237
                  break;
1238
                  
1239
              }
1240
              index++;
1241
          }
1200 1242
          
1201
      } catch (Exception e) { // Catch is generic since HZ throws RuntimeException
1202
        throw new NotFound("4854", "No record found for: " + pid.getValue() +
1203
            " : " + e.getMessage());
1204
        
1205
      }
1243
          // add the new replica item
1244
          replicas.add(replica);
1245
          systemMetadata.setReplicaList(replicas);
1206 1246
          
1207
      // set the status for the replica
1208
      List<Replica> replicas = systemMetadata.getReplicaList();
1209
      NodeReference replicaNode = replica.getReplicaMemberNode();
1210
      int index = 0;
1211
      for (Replica listedReplica: replicas) {
1247
          // update the metadata
1248
          try {
1249
              systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
1250
              systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
1251
              HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata);
1252
            
1253
          } catch (Exception e) {
1254
              throw new ServiceFailure("4852", e.getMessage());
1212 1255
          
1213
          // remove the replica that we are replacing
1214
          if ( replicaNode.getValue().equals(listedReplica.getReplicaMemberNode().getValue())) {
1215
              replicas.remove(index);
1216
              break;
1217
              
1218 1256
          }
1219
          index++;
1220
      }
1221
      
1222
      // add the new replica item
1223
      replicas.add(replica);
1224
      systemMetadata.setReplicaList(replicas);
1225
      
1226
      // update the metadata
1227
      try {
1228
          systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
1229
          systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
1230
          HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata);
1257
          
1258
    } catch (Exception e) {
1259
        throw new ServiceFailure("4852", e.getMessage());
1260

  
1261
    } finally {
1262
        lock.unlock();
1263
        logMetacat.debug("Unlocked identifier " + pid.getValue());
1231 1264
        
1232
      } catch (Exception e) {
1233
          throw new ServiceFailure("4852", e.getMessage());
1234
      
1235
      } finally {
1236
          lock.unlock();
1237
          logMetacat.debug("Unlocked identifier " + pid.getValue());
1238
          
1239
      }
1265
    }
1240 1266
    
1241 1267
      return true;
1242 1268
      
1243 1269
  }
1244 1270
  
1245 1271
    @Override
1246
    public ObjectList listObjects(Session session, Date startTime, 
1247
            Date endTime, ObjectFormatIdentifier formatid, Boolean replicaStatus,
1248
            Integer start, Integer count)
1272
  public ObjectList listObjects(Session session, Date startTime, 
1273
      Date endTime, ObjectFormatIdentifier formatid, Boolean replicaStatus,
1274
      Integer start, Integer count)
1249 1275
      throws InvalidRequest, InvalidToken, NotAuthorized, NotImplemented,
1250 1276
      ServiceFailure {
1251 1277
      
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
581 581
      }
582 582
      SystemMetadata systemMetadata = null;
583 583
      try {
584
        HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
585 584
        systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
586
        HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
587 585
        
588 586
      } catch (Exception e) {
589 587
        // convert hazelcast RuntimeException to NotFound
......
670 668
    String pidStr = pid.getValue();
671 669
    SystemMetadata systemMetadata = null;
672 670
    try {
673
        HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
674 671
        systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
675
        HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
676 672

  
677 673
    } catch (Exception e) {
678 674
        // convert Hazelcast RuntimeException to NotFound
......
680 676
            pid.getValue() + ". The error message was: " + e.getMessage());
681 677
        throw new NotFound("1800", "No record found for " + pidStr);
682 678
        
683
    } finally {
684
        HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
685
        
686
    }
679
    } 
687 680
    
688 681
    // throw not found if it was not found
689 682
    if (systemMetadata == null) {
......
1031 1024
   * 
1032 1025
   * @param sysMeta - the system metadata object in the system to update
1033 1026
   */
1034
  protected void updateSystemMetadata(SystemMetadata sysMeta)
1035
    throws ServiceFailure {
1036
      
1037
    logMetacat.debug("D1NodeService.updateSystemMetadata() called.");
1038
    sysMeta.setDateSysMetadataModified(new Date());
1039
    try {
1040
    	HazelcastService.getInstance().getSystemMetadataMap().lock(sysMeta.getIdentifier());
1041
    	HazelcastService.getInstance().getSystemMetadataMap().put(sysMeta.getIdentifier(), sysMeta);
1042
    	HazelcastService.getInstance().getSystemMetadataMap().unlock(sysMeta.getIdentifier());
1043
	} catch (Exception e) {
1044
		throw new ServiceFailure("4862", e.getMessage());
1045
	} finally {
1046
		HazelcastService.getInstance().getSystemMetadataMap().unlock(sysMeta.getIdentifier());
1047
	}
1048
      
1049
  }
1027
    protected void updateSystemMetadata(SystemMetadata sysMeta)
1028
        throws ServiceFailure {
1029

  
1030
        logMetacat.debug("D1NodeService.updateSystemMetadata() called.");
1031
        sysMeta.setDateSysMetadataModified(new Date());
1032
        try {
1033
            HazelcastService.getInstance().getSystemMetadataMap().lock(sysMeta.getIdentifier());
1034
            HazelcastService.getInstance().getSystemMetadataMap().put(sysMeta.getIdentifier(), sysMeta);
1035

  
1036
        } catch (Exception e) {
1037
            throw new ServiceFailure("4862", e.getMessage());
1038

  
1039
        } finally {
1040
            HazelcastService.getInstance().getSystemMetadataMap().unlock(sysMeta.getIdentifier());
1041

  
1042
        }
1043

  
1044
    }
1050 1045
  
1051 1046
  /**
1052 1047
   * Given a Permission, returns a list of all permissions that it encompasses

Also available in: Unified diff