test values cache

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

test values cache

Евгений-8
Hello Wolfgang!

I add some code for test values cache.



I have next document

<test>test<a>a<b>b</b></a></test>


run next queries:

data(/test)
data(/tets/a)
data(/test/a/b)
update delete /test/a/b

and have next log:



2005-10-07 12:33:57,128 [P1-9] DEBUG (XQuery.java [compile]:114) - Query
diagnostics:
data(/ROOT/child::test)
2005-10-07 12:33:57,132 [P1-9] DEBUG (XQuery.java [compile]:116) -
Compilation took 176
2005-10-07 12:33:57,138 [P1-9] DEBUG (XQueryContext.java
[getStaticallyKnownDocuments]:527) - reading collection /db
2005-10-07 12:33:57,927 [P1-9] DEBUG (CacheManager.java
[requestMem]:176) - Growing cache collections.dbx (a
org.exist.storage.cache.LRUCache) from 64 to 80
2005-10-07 12:33:57,957 [P1-9] DEBUG (CacheManager.java
[requestMem]:176) - Growing cache collections.dbx (a
org.exist.storage.cache.LRUCache) from 80 to 100
2005-10-07 12:33:58,109 [P1-9] DEBUG (CacheManager.java
[requestMem]:176) - Growing cache collections.dbx (a
org.exist.storage.cache.LRUCache) from 100 to 125
2005-10-07 12:33:58,168 [P1-9] DEBUG (CacheManager.java
[requestMem]:176) - Growing cache collections.dbx (a
org.exist.storage.cache.LRUCache) from 125 to 156
2005-10-07 12:33:58,238 [P1-9] DEBUG (CacheManager.java
[requestMem]:176) - Growing cache collections.dbx (a
org.exist.storage.cache.LRUCache) from 156 to 195
2005-10-07 12:33:58,637 [P1-9] DEBUG (DOMFile.java [getNodeValue]:1784)
- cache node 121822464966656
2005-10-07 12:33:58,641 [P1-9] DEBUG (HTTPUtils.java
[addLastModifiedHeader]:61) - mostRecentDocumentTime: 0
2005-10-07 12:33:58,642 [P1-9] DEBUG (HTTPUtils.java
[addLastModifiedHeader]:61) - mostRecentDocumentTime: 0
2005-10-07 12:33:58,643 [P1-9] INFO  (RpcConnection.java [doQuery]:307)
- query took 1507ms.
2005-10-07 12:33:58,646 [P1-9] DEBUG (RpcConnection.java [queryP]:1442)
- found 1
2005-10-07 12:34:01,936 [P1-9] DEBUG (XQuery.java [compile]:114) - Query
diagnostics:
data(/ROOT/child::test/child::a)
2005-10-07 12:34:01,937 [P1-9] DEBUG (XQuery.java [compile]:116) -
Compilation took 4
2005-10-07 12:34:01,938 [P1-9] DEBUG (XQueryContext.java
[getStaticallyKnownDocuments]:527) - reading collection /db
2005-10-07 12:34:02,222 [P1-9] DEBUG (DOMFile.java [getNodeValue]:1784)
- cache node 121822464966658
2005-10-07 12:34:02,223 [P1-9] DEBUG (HTTPUtils.java
[addLastModifiedHeader]:61) - mostRecentDocumentTime: 0
2005-10-07 12:34:02,225 [P1-9] DEBUG (HTTPUtils.java
[addLastModifiedHeader]:61) - mostRecentDocumentTime: 0
2005-10-07 12:34:02,226 [P1-9] INFO  (RpcConnection.java [doQuery]:307)
- query took 288ms.
2005-10-07 12:34:02,228 [P1-9] DEBUG (RpcConnection.java [queryP]:1442)
- found 1
2005-10-07 12:34:08,075 [P1-9] DEBUG (XQuery.java [compile]:114) - Query
diagnostics:
data(/ROOT/child::test/child::a/child::b)
2005-10-07 12:34:08,076 [P1-9] DEBUG (XQuery.java [compile]:116) -
Compilation took 4
2005-10-07 12:34:08,077 [P1-9] DEBUG (XQueryContext.java
[getStaticallyKnownDocuments]:527) - reading collection /db
2005-10-07 12:34:08,214 [P1-9] DEBUG (DOMFile.java [getNodeValue]:1784)
- cache node 121822460772356
2005-10-07 12:34:08,215 [P1-9] DEBUG (HTTPUtils.java
[addLastModifiedHeader]:61) - mostRecentDocumentTime: 0
2005-10-07 12:34:08,230 [P1-9] DEBUG (HTTPUtils.java
[addLastModifiedHeader]:61) - mostRecentDocumentTime: 0
2005-10-07 12:34:08,231 [P1-9] INFO  (RpcConnection.java [doQuery]:307)
- query took 154ms.
2005-10-07 12:34:08,238 [P1-9] DEBUG (RpcConnection.java [queryP]:1442)
- found 1
2005-10-07 12:34:14,301 [P1-9] DEBUG (XQuery.java [compile]:114) - Query
diagnostics:

2005-10-07 12:34:14,302 [P1-9] DEBUG (XQuery.java [compile]:116) -
Compilation took 5
2005-10-07 12:34:14,303 [P1-9] DEBUG (XQueryContext.java
[getStaticallyKnownDocuments]:527) - reading collection /db/temp
2005-10-07 12:34:14,423 [P1-9] DEBUG (DOMFile.java [removeNode]:1451) -
clear cache from removeNode for node121822452383749
2005-10-07 12:34:14,425 [P1-9] DEBUG (NativeBroker.java
[removeNode]:2240) - clear cache from nativebroker for node: 121822452383748
2005-10-07 12:34:14,426 [P1-9] DEBUG (NativeBroker.java
[removeNode]:2240) - clear cache from nativebroker for node: 121822452383746
2005-10-07 12:34:14,427 [P1-9] DEBUG (NativeBroker.java
[removeNode]:2240) - clear cache from nativebroker for node: 121822452383744
2005-10-07 12:34:14,428 [P1-9] DEBUG (DOMFile.java [removeNode]:1451) -
clear cache from removeNode for node121822460772356
2005-10-07 12:34:14,430 [P1-9] DEBUG (NativeBroker.java
[removeNode]:2240) - clear cache from nativebroker for node: 121822452383746
2005-10-07 12:34:14,431 [P1-9] DEBUG (NativeBroker.java
[removeNode]:2240) - clear cache from nativebroker for node: 121822452383744
2005-10-07 12:34:14,435 [P1-9] DEBUG (DOMFile.java [update]:1719) -
clear cache from update for node121822452383746
2005-10-07 12:34:14,438 [P1-9] DEBUG (HTTPUtils.java
[addLastModifiedHeader]:61) - mostRecentDocumentTime: 0
2005-10-07 12:34:14,439 [P1-9] DEBUG (HTTPUtils.java
[addLastModifiedHeader]:61) - mostRecentDocumentTime: 0
2005-10-07 12:34:14,441 [P1-9] INFO  (RpcConnection.java [doQuery]:307)
- query took 138ms.
2005-10-07 12:34:14,453 [P1-9] DEBUG (RpcConnection.java [queryP]:1442)
- found 0




Index: eXist-1.0/src/org/exist/storage/NativeBroker.java
===================================================================
RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/NativeBroker.java,v
retrieving revision 1.195
diff -u -r1.195 NativeBroker.java
--- eXist-1.0/src/org/exist/storage/NativeBroker.java 4 Oct 2005 11:10:51 -0000 1.195
+++ eXist-1.0/src/org/exist/storage/NativeBroker.java 7 Oct 2005 09:53:19 -0000
@@ -2233,6 +2233,15 @@
  }
  }
  .run();
+        
+        Node parent = node.getParentNode();
+        while (parent!=null){
+            long p = ((NodeImpl)parent).getInternalAddress();
+            LOG.debug("clear cache from nativebroker for node: "+p);
+            domDb.clearValuesCache(p);
+            parent = parent.getParentNode();
+        }
+                
  NodeProxy tempProxy = new NodeProxy(doc, gid, node.getInternalAddress());
  QName qname;
  switch (nodeType) {

Index: eXist-1.0/src/org/exist/storage/dom/DOMFile.java
===================================================================
RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/dom/DOMFile.java,v
retrieving revision 1.7
diff -u -r1.7 DOMFile.java
--- eXist-1.0/src/org/exist/storage/dom/DOMFile.java 30 Sep 2005 09:43:47 -0000 1.7
+++ eXist-1.0/src/org/exist/storage/dom/DOMFile.java 7 Oct 2005 09:55:26 -0000
@@ -60,6 +60,7 @@
 import org.exist.util.Lockable;
 import org.exist.util.ReadOnlyException;
 import org.exist.util.hashtable.Object2LongIdentityHashMap;
+import org.exist.util.hashtable.Long2ObjectHashMap;
 import org.exist.util.sanity.SanityCheck;
 import org.exist.xquery.TerminatedException;
 import org.w3c.dom.Node;
@@ -151,6 +152,8 @@
 
  public final static long DATA_SYNC_PERIOD = 4200;
 
+    private Long2ObjectHashMap values = new Long2ObjectHashMap(); // cach for values  of nodes
+
  private final Cache dataCache;
 
  private BTreeFileHeader fileHeader;
@@ -1425,7 +1428,16 @@
  }
  }
 
- /**
+    /**
+     * Clear cash values for node with address p
+     *
+     * @param p
+     */
+     public void clearValuesCache(long p){
+         values.remove(p);
+     }
+
+     /**
  * Physically remove a node. The data of the node will be removed from the
  * page and the occupied space is freed.
  *
@@ -1436,6 +1448,8 @@
  }
 
  public void removeNode(Txn transaction, long p) {
+        LOG.debug("clear cache from removeNode for node"+p);        
+        clearValuesCache(p); //remove node's value from cahce
  RecordPos rec = findRecord(p);
  final int startOffset = rec.offset - 2;
  final DOMFilePageHeader ph = rec.page.getPageHeader();
@@ -1570,6 +1584,8 @@
  * @param p
  */
  public void removeAll(Txn transaction, long p) {
+         LOG.debug("clear cache from removeAll for node"+p);        
+         clearValuesCache(p); //remove node's value from cahce
 // StringBuffer debug = new StringBuffer();
 // debug.append("Removed pages: ");
  long pnum = StorageAddress.pageFromPointer(p);
@@ -1699,6 +1715,10 @@
  */
  public void update(Txn transaction, long p, byte[] value)
  throws ReadOnlyException {
+                
+        LOG.debug("clear cache from update for node"+p);        
+        clearValuesCache(p); //remove node's value from cahce
+
  RecordPos rec = findRecord(p);
         
  short l = ByteConversion.byteToShort(rec.page.data, rec.offset);
@@ -1737,6 +1757,14 @@
  address = findValue(this, proxy);
  if (address == BTree.KEY_NOT_FOUND)
  return null;
+            
+ String value;
+
+            value = (String)values.get(address); //get value from cache, if cached ..
+            if (value!=null)
+                return value;
+            // ... otherwise calculate value
+            
  final RecordPos rec = findRecord(address);
  SanityCheck.THROW_ASSERT(rec != null,
  "Node data could not be found! Page: "
@@ -1746,12 +1774,16 @@
  final ByteArrayOutputStream os = new ByteArrayOutputStream();
  getNodeValue(os, rec, true, addWhitespace);
  final byte[] data = os.toByteArray();
- String value;
+            
  try {
  value = new String(data, "UTF-8");
  } catch (UnsupportedEncodingException e) {
  value = new String(data);
  }
+            
+            LOG.debug("cache node "+address);
+            values.put(address,value); //add value in cache
+            
  return value;
  } catch (BTreeException e) {
  LOG.warn("btree error while reading node value", e);