more synchronization in plasmaWordIndex

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2385 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 19 years ago
parent f43c90fa98
commit 328f9859a5

@ -200,9 +200,9 @@ public final class plasmaWordIndex extends indexAbstractRI implements indexRI {
} }
public void flushCacheSome() { public void flushCacheSome() {
int flushCount = ramCache.wSize() / 500; int flushCount = ramCache.wSize() / 350;
if (flushCount > 80) flushCount = 80; if (flushCount > 80) flushCount = 80;
if (flushCount < 10) flushCount = Math.min(10, ramCache.wSize()); if (flushCount < 20) flushCount = Math.min(20, ramCache.wSize());
flushCache(flushCount); flushCache(flushCount);
} }
@ -321,6 +321,7 @@ public final class plasmaWordIndex extends indexAbstractRI implements indexRI {
public indexContainer getContainer(String wordHash, boolean deleteIfEmpty, long maxTime) { public indexContainer getContainer(String wordHash, boolean deleteIfEmpty, long maxTime) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
synchronized (ramCache) {
// get from cache // get from cache
indexContainer container = ramCache.getContainer(wordHash, true, -1); indexContainer container = ramCache.getContainer(wordHash, true, -1);
@ -355,6 +356,7 @@ public final class plasmaWordIndex extends indexAbstractRI implements indexRI {
container.add(backend.getContainer(wordHash, deleteIfEmpty, (maxTime < 0) ? -1 : maxTime), -1); container.add(backend.getContainer(wordHash, deleteIfEmpty, (maxTime < 0) ? -1 : maxTime), -1);
return container; return container;
} }
}
public Set getContainers(Set wordHashes, boolean deleteIfEmpty, boolean interruptIfEmpty, long maxTime) { public Set getContainers(Set wordHashes, boolean deleteIfEmpty, boolean interruptIfEmpty, long maxTime) {
@ -362,6 +364,7 @@ public final class plasmaWordIndex extends indexAbstractRI implements indexRI {
HashSet containers = new HashSet(); HashSet containers = new HashSet();
String singleHash; String singleHash;
indexContainer singleContainer; indexContainer singleContainer;
synchronized (ramCache) {
Iterator i = wordHashes.iterator(); Iterator i = wordHashes.iterator();
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
long remaining; long remaining;
@ -382,10 +385,12 @@ public final class plasmaWordIndex extends indexAbstractRI implements indexRI {
containers.add(singleContainer); containers.add(singleContainer);
} }
}
return containers; return containers;
} }
public int size() { public int size() {
synchronized (ramCache) {
if (useCollectionIndex) if (useCollectionIndex)
return java.lang.Math.max(collections.size(), return java.lang.Math.max(collections.size(),
java.lang.Math.max(assortmentCluster.size(), java.lang.Math.max(assortmentCluster.size(),
@ -394,9 +399,11 @@ public final class plasmaWordIndex extends indexAbstractRI implements indexRI {
return java.lang.Math.max(assortmentCluster.size(), return java.lang.Math.max(assortmentCluster.size(),
java.lang.Math.max(backend.size(), ramCache.size())); java.lang.Math.max(backend.size(), ramCache.size()));
} }
}
public int indexSize(String wordHash) { public int indexSize(String wordHash) {
int size = 0; int size = 0;
synchronized (ramCache) {
try { try {
plasmaWordIndexFile entity = backend.getEntity(wordHash, true, -1); plasmaWordIndexFile entity = backend.getEntity(wordHash, true, -1);
if (entity != null) { if (entity != null) {
@ -407,15 +414,18 @@ public final class plasmaWordIndex extends indexAbstractRI implements indexRI {
if (useCollectionIndex) size += collections.indexSize(wordHash); if (useCollectionIndex) size += collections.indexSize(wordHash);
size += assortmentCluster.indexSize(wordHash); size += assortmentCluster.indexSize(wordHash);
size += ramCache.indexSize(wordHash); size += ramCache.indexSize(wordHash);
}
return size; return size;
} }
public synchronized void close(int waitingBoundSeconds) { public synchronized void close(int waitingBoundSeconds) {
synchronized (ramCache) {
ramCache.close(waitingBoundSeconds); ramCache.close(waitingBoundSeconds);
if (useCollectionIndex) collections.close(-1); if (useCollectionIndex) collections.close(-1);
assortmentCluster.close(-1); assortmentCluster.close(-1);
backend.close(10); backend.close(10);
} }
}
public synchronized indexContainer deleteContainer(String wordHash) { public synchronized indexContainer deleteContainer(String wordHash) {
synchronized (ramCache) { synchronized (ramCache) {
@ -458,8 +468,10 @@ public final class plasmaWordIndex extends indexAbstractRI implements indexRI {
// urlHash assigned. This can only work if the entry is really fresh // urlHash assigned. This can only work if the entry is really fresh
// and can be found in the RAM cache // and can be found in the RAM cache
// this returns the number of deletion that had been possible // this returns the number of deletion that had been possible
synchronized (ramCache) {
return ramCache.tryRemoveURLs(urlHash); return ramCache.tryRemoveURLs(urlHash);
} }
}
public static final int RL_RAMCACHE = 0; public static final int RL_RAMCACHE = 0;
public static final int RL_COLLECTIONS = 1; // the new index structure public static final int RL_COLLECTIONS = 1; // the new index structure
@ -472,6 +484,7 @@ public final class plasmaWordIndex extends indexAbstractRI implements indexRI {
kelondroOrder containerOrder = new indexContainerOrder((kelondroOrder) indexOrder.clone()); kelondroOrder containerOrder = new indexContainerOrder((kelondroOrder) indexOrder.clone());
containerOrder.rotate(startHash.getBytes()); containerOrder.rotate(startHash.getBytes());
TreeSet containers = new TreeSet(containerOrder); TreeSet containers = new TreeSet(containerOrder);
synchronized (ramCache) {
Iterator i = wordContainers(startHash, resourceLevel, rot); Iterator i = wordContainers(startHash, resourceLevel, rot);
if (resourceLevel == plasmaWordIndex.RL_RAMCACHE) count = Math.min(ramCache.wSize(), count); if (resourceLevel == plasmaWordIndex.RL_RAMCACHE) count = Math.min(ramCache.wSize(), count);
indexContainer container; indexContainer container;
@ -482,6 +495,7 @@ public final class plasmaWordIndex extends indexAbstractRI implements indexRI {
count--; count--;
} }
} }
}
return containers; return containers;
} }

Loading…
Cancel
Save