Removed references locks
This commit is contained in:
parent
7fd7497464
commit
f030a96608
@ -110,14 +110,9 @@ public class DatabaseReferencesMetadata implements IReferencesMetadata {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long newReference(long index, int size) throws IOException {
|
public long newReference(long index, int size) throws IOException {
|
||||||
lock.writeLock().lock();
|
|
||||||
long newReference;
|
long newReference;
|
||||||
try {
|
newReference = firstFreeReference.getAndIncrement();
|
||||||
newReference = firstFreeReference.getAndIncrement();
|
cache.put(newReference, new ReferenceInfo(index, size, BLANK_DATA_CLEANER), true, true);
|
||||||
cache.put(newReference, new ReferenceInfo(index, size, BLANK_DATA_CLEANER), true);
|
|
||||||
} finally {
|
|
||||||
lock.writeLock().unlock();
|
|
||||||
}
|
|
||||||
return newReference;
|
return newReference;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +120,7 @@ public class DatabaseReferencesMetadata implements IReferencesMetadata {
|
|||||||
public void editReference(long reference, ReferenceInfo info) throws IOException {
|
public void editReference(long reference, ReferenceInfo info) throws IOException {
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
cache.put(reference, info, true);
|
cache.put(reference, info, true, false);
|
||||||
} finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
lock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
@ -135,7 +130,7 @@ public class DatabaseReferencesMetadata implements IReferencesMetadata {
|
|||||||
public void deleteReference(long reference) throws IOException {
|
public void deleteReference(long reference) throws IOException {
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
cache.put(reference, NONEXISTENT_REFERENCE_INFO, true);
|
cache.put(reference, NONEXISTENT_REFERENCE_INFO, true, false);
|
||||||
} finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
lock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
|
@ -44,20 +44,31 @@ public class DatabaseReferencesMetadataCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void put(long reference, ReferenceInfo info, boolean modified) throws IOException {
|
public void put(long reference, ReferenceInfo info, boolean isModified, boolean isNew) throws IOException {
|
||||||
if (closed) throw new IOException("Cache already closed!");
|
if (closed) throw new IOException("Cache already closed!");
|
||||||
lock.writeLock().lock();
|
if (isNew) {
|
||||||
|
lock.readLock().lock();
|
||||||
|
} else {
|
||||||
|
lock.writeLock().lock();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (info.getCleanerId() == 0) {
|
if (info.getCleanerId() == 0) {
|
||||||
throw new IOException("Null cleaner id");
|
throw new IOException("Null cleaner id");
|
||||||
}
|
}
|
||||||
referencesInfos.put(reference, info);
|
referencesInfos.put(reference, info);
|
||||||
if (modified) {
|
if (isModified) {
|
||||||
modifiedInfos.put(reference, info);
|
modifiedInfos.put(reference, info);
|
||||||
}
|
}
|
||||||
flush();
|
// If it's new you can't flush because you have only the read permission
|
||||||
|
if (!isNew) {
|
||||||
|
flush();
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
if (isNew) {
|
||||||
|
lock.readLock().unlock();
|
||||||
|
} else {
|
||||||
|
lock.writeLock().unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user