Would it make sense to return the Condition so we can check that we are
unlocking from the actual owner of the lock?
On Thursday 05 June 2008 16:32, j16sdiz at freenetproject.org wrote:
> Author: j16sdiz
> Date: 2008-06-05 15:32:00 +0000 (Thu, 05 Jun 2008)
> New Revision: 20220
>
> Modified:
>
branches/saltedhashstore/freenet/src/freenet/store/SaltedHashFreenetStore.java
> Log:
> lock old offsets only on fetch()
>
>
> Modified:
branches/saltedhashstore/freenet/src/freenet/store/SaltedHashFreenetStore.java
> ===================================================================
> ---
branches/saltedhashstore/freenet/src/freenet/store/SaltedHashFreenetStore.java
2008-06-05 15:31:35 UTC (rev 20219)
> +++
branches/saltedhashstore/freenet/src/freenet/store/SaltedHashFreenetStore.java
2008-06-05 15:32:00 UTC (rev 20220)
> @@ -119,7 +119,7 @@
>
> configLock.readLock().lock();
> try {
> - boolean locked = lockPlainKey(routingKey);
> + boolean locked = lockPlainKey(routingKey, true);
> if (!locked) {
> if (logDEBUG)
> Logger.debug(this, "cannot lock key: "
> +
HexUtil.bytesToHex(routingKey) + ", shutting down?");
> @@ -145,7 +145,7 @@
> return null;
> }
> } finally {
> - unlockPlainKey(routingKey);
> + unlockPlainKey(routingKey, true);
> }
> } finally {
> configLock.readLock().unlock();
> @@ -203,7 +203,7 @@
>
> configLock.readLock().lock();
> try {
> - boolean locked = lockPlainKey(routingKey);
> + boolean locked = lockPlainKey(routingKey, false);
> if (!locked) {
> if (logDEBUG)
> Logger.debug(this, "cannot lock key: "
> +
HexUtil.bytesToHex(routingKey) + ", shutting down?");
> @@ -259,7 +259,7 @@
> writeEntry(entry, offset[0]);
> writes.incrementAndGet();
> } finally {
> - unlockPlainKey(routingKey);
> + unlockPlainKey(routingKey, false);
> }
> } finally {
> configLock.readLock().unlock();
> @@ -1221,12 +1221,12 @@
> * @param plainKey
> * @return <code>true</code> if all the offsets are locked.
> */
> - private boolean lockPlainKey(byte[] plainKey) {
> - return lockDigestedKey(getDigestedRoutingKey(plainKey));
> + private boolean lockPlainKey(byte[] plainKey, boolean usePrevStoreSize)
> {
> + return lockDigestedKey(getDigestedRoutingKey(plainKey),
usePrevStoreSize);
> }
>
> - private void unlockPlainKey(byte[] plainKey) {
> - unlockDigestedKey(getDigestedRoutingKey(plainKey));
> + private void unlockPlainKey(byte[] plainKey, boolean usePrevStoreSize) {
> + unlockDigestedKey(getDigestedRoutingKey(plainKey),
> usePrevStoreSize);
> }
>
> /**
> @@ -1236,14 +1236,14 @@
> * @param digestedKey
> * @return <code>true</code> if all the offsets are locked.
> */
> - private boolean lockDigestedKey(byte[] digestedKey) {
> + private boolean lockDigestedKey(byte[] digestedKey, boolean
usePrevStoreSize) {
> // use a set to prevent duplicated offsets,
> // a sorted set to prevent deadlocks
> SortedSet<Long> offsets = new TreeSet<Long>();
> long[] offsetArray = getOffsetFromDigestedKey(digestedKey,
> storeSize);
> for (long offset : offsetArray)
> offsets.add(offset);
> - if (prevStoreSize != 0) {
> + if (usePrevStoreSize && prevStoreSize != 0) {
> offsetArray = getOffsetFromDigestedKey(digestedKey,
> prevStoreSize);
> for (long offset : offsetArray)
> offsets.add(offset);
> @@ -1267,13 +1267,13 @@
> }
> }
>
> - private void unlockDigestedKey(byte[] digestedKey) {
> + private void unlockDigestedKey(byte[] digestedKey, boolean
usePrevStoreSize) {
> // use a set to prevent duplicated offsets
> SortedSet<Long> offsets = new TreeSet<Long>();
> long[] offsetArray = getOffsetFromDigestedKey(digestedKey,
> storeSize);
> for (long offset : offsetArray)
> offsets.add(offset);
> - if (prevStoreSize != 0) {
> + if (usePrevStoreSize && prevStoreSize != 0) {
> offsetArray = getOffsetFromDigestedKey(digestedKey,
> prevStoreSize);
> for (long offset : offsetArray)
> offsets.add(offset);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL:
<https://emu.freenetproject.org/pipermail/devl/attachments/20080712/c0e121ee/attachment.pgp>