Revision 6858
Added by Chris Jones over 12 years ago
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
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.