You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Cedric Vidal <dr...@atilla.org> on 2003/08/22 16:24:20 UTC

Custom Action / Calls / Caching Issue: Bug or behavior ??

Hi,

I observed a strange behavior in cocoon-2.1 stable regarding the bahavior of 
caching when Actions are involved, and I don't know wether it's a bug or a 
feature. This mail is pretty long and I apologize for that, but in order to get 
a clear view of the issue and how to reproduce it, i felt like I had to detail 
the context and the steps required to reproduce the strange behavior.

Note that I considered submiting this as a bug report, but I'm not really 
confortable with bugzilla and I'm not event sure that the following is a bug ...

First of all, I will describe the overall situation and then, i will describe 
how the problem arises. Here follows the description of the situation:

-------------------------------------------------------------------
 What I have
-------------------------------------------------------------------
I have a set of source xml documents which are identified by a name and a 
language:
	- xml/java/javadoc.xml	( xml/{language}/{test}.xml )
I have a set of xsl transformations which are identified by their source 
language and their target language:
	- xsl/java-oop.xsl	( xsl/{source-language}-{target-language}.xsl )
	- xsl/oop-pp.xsl
	- xsl/pp-p.xsl
	- ...
I have a file which describes a flow (named process-map.xml), ie it describes 
the sequence of transformations which will be applied to a source document of a 
given language:

<?xml version="1.0" encoding="ISO-8859-1"?>
<process xmlns="http://lassi.eisti.fr/Languages/Process">
	<!-- ... -->
	<relations>
		<!-- ... -->
		<relation from="java" to="oop"/>
		<relation from="oop" to="pp"/>
		<relation from="pp" to="p"/>
		<!-- ... -->
	</relations>
	<!-- ... -->
</process>

For example, for a source document of the language java, i want it to go 
through steps 'oop', 'pp' and 'p', ie I want to apply stylesheets: java-
oop.xsl, oop-pp.xsl and pp-p.xsl.

-------------------------------------------------------------------
 What I want
-------------------------------------------------------------------
When i request a uri given a name and a language, I want my source xml document 
of that given name and that given language to go trough the set of xsl 
transformations described in the process-map for that language.

-------------------------------------------------------------------
 What I have already developped and works (at least seems to :o)
-------------------------------------------------------------------
An action named StepManagerAction which given the process-map.xml, a language 
and the current step of the transformations returns the next step to 
accomplish. For example, for a source document of the language 'java' and at 
transformation step 'oop', the StepManagerAction will return 'pp'. If the 
current step is last step 'p', then the action will return null, hence 
finishing the transformations.

This action works with <map:call/> statements called recursively until the 
action returns null;

You will find the source code of the StepManagerAction and its dependencies as 
an attachement to this mail.

-------------------------------------------------------------------
 The sitemap used follows:
-------------------------------------------------------------------

<?xml version="1.0" encoding="ISO-8859-1"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
 <map:components>
  <map:readers default="resource"/>
  <map:generators default="file"/>
  <map:transformers default="xslt"/>
  <map:serializers default="xml"/>
  <map:matchers default="wildcard"/>
  
  <map:actions>
   <map:action logger="sitemap.action.stepper" name="stepManager"
         src="fr.eisti.lassi.elearning.cocoon.sitemap.StepManagerAction"/>
  </map:actions>

 </map:components>

 <map:pipelines>
  <map:pipeline>
    
    <!-- I want to match a source document which follows the -->
    <!-- uri {language}/{name}.xml                           -->
    <map:match pattern="*/*.xml">

      <!-- Here is my source XML document -->
      <map:generate src="xml/{1}/{2}.xml"/>

      <!-- Here is the first call to the stepManager -->
      <map:call resource="stepper">
        <map:parameter name="lang" value="{1}"/>
        <map:parameter name="step" value="{1}"/>
      </map:call>

      <!-- We display the result -->
      <map:serialize type="xml"/>
    </map:match>

    <!-- Here is the process-map -->
    <map:match pattern="process-map.xml">
      <map:generate src="process-map.xml"/>
      <map:serialize type="xml"/>
    </map:match>
    
  </map:pipeline>
 </map:pipelines>
 
 <map:resources>
   <map:resource name="stepper">

     <!-- Here is the action which will enable the flow to be controlled -->
     <!-- by process-map.xml. If no more step is to be applied, then the -->
     <!-- action returns null and the recursivity stops                  -->
     <map:act type="stepManager">
       <map:parameter name="process-map" value="cocoon:/process-map.xml"/>
       <map:parameter name="lang" value="{lang}"/>
       <map:parameter name="step" value="{step}"/>

         <!-- Here I apply the transformation of the current target step -->
         <!-- Note that the current target step is the next source step  -->
         <map:transform src="xsl/{../lang}-{next}.xsl"/>

         <!-- Here i call myself recursively with the new current step -->
         <map:call resource="stepper">
           <map:parameter name="lang" value="{../lang}"/>
           <map:parameter name="step" value="{next}"/>
         </map:call>

     </map:act>
   </map:resource>
 </map:resources>

</map:sitemap>

-------------------------------------------------------------------
 The problem ...
-------------------------------------------------------------------
The problem arises in a very specific situation, so i'll try to describe the 
steps needed to reproduce the issue and the overall state after each step. To 
highlight what's going wrong, I describe two testcases, in the first one, 
everything works as expected, but in the second one, it doesn't :(

-------------------------------------------------------------------
 How do I track what's happening ?
-------------------------------------------------------------------
I track the state of the MRUMemoryStore by hitting the page /samples/status.html
I can also tell by the content of the output which transformations have been 
applied.
Note that I only show chunks that are relevant.

-------------------------------------------------------------------
 Here we go
-------------------------------------------------------------------

--------------------------------------------------
 Successful testcase
--------------------------------------------------

----------------------------------
 Initial situation:
----------------------------------
- Process-map.xml
	<relation from="java" to="oop"/>
	<relation from="oop" to="pp"/>
	<relation from="pp" to="p"/>
- MRUMemoryStore
	Empty

----------------------------------
 First Hit of java/test.xml
----------------------------------
- Process-map
	<relation from="java" to="oop"/>
	<relation from="oop" to="pp"/>
	<relation from="pp" to="p"/>

- MRUMemoryStore

1 PK_G-file-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/process-map.xml_S-xml-1 (class: 
org.apache.cocoon.caching.CachedResponse) 

2 PK_G-file-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/process-map.xml (class: 
org.apache.cocoon.caching.CachedResponse) 

3 cocoon://samples/lassi/process-map.xml?pipelinehash=4251363787339917931 
(class: fr.eisti.lassi.elearning.cocoon.sitemap.ProcessMapEntry) 

4 PK_G-file-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/xml/java/javadoc.xml_T-xslt-file:/C:/TEMP/cocoon-
2.1-src/cocoon-2.1/src/webapp/samples/lassi/xsl/java-oop.xsl_T-xslt-
file:/C:/TEMP/cocoon-2.1-src/cocoon-2.1/src/webapp/samples/lassi/xsl/java-
pp.xsl_T-xslt-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/xsl/java-p.xsl_S-xml-1 (class: 
org.apache.cocoon.caching.CachedResponse) 

- Transformations applied
	java-oop.xsl, oop-pp.xsl, pp-p.xsl

- Comment
Here, everything works fine, the StepManagerAction created the ProcessMap 
object out of process-map.xml and stored the object ProcessMap into the store 
(entry 3). Then ProcessMap returned the good steps and the right 
transformations have been applied.
The result has been cached (entry 4) with a key also telling that the good 
transformations have been applied.

----------------------------------
 Second Hit of java/test.xml after
 a modification of process-map.xml
----------------------------------
- Process-map
I remove two steps to keep only the following
	<relation from="java" to="oop"/>

- MRUMemoryStore

1 PK_G-file-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/xml/java/javadoc.xml_T-xslt-file:/C:/TEMP/cocoon-
2.1-src/cocoon-2.1/src/webapp/samples/lassi/xsl/java-oop.xsl_S-xml-1 (class: 
org.apache.cocoon.caching.CachedResponse) 

2 PK_G-file-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/process-map.xml_S-xml-1 (class: 
org.apache.cocoon.caching.CachedResponse) 

3 PK_G-file-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/process-map.xml (class: 
org.apache.cocoon.caching.CachedResponse) 

4 cocoon://samples/lassi/process-map.xml?pipelinehash=4251363787339917931 
(class: fr.eisti.lassi.elearning.cocoon.sitemap.ProcessMapEntry) 

5 PK_G-file-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/xml/java/javadoc.xml_T-xslt-file:/C:/TEMP/cocoon-
2.1-src/cocoon-2.1/src/webapp/samples/lassi/xsl/java-oop.xsl_T-xslt-
file:/C:/TEMP/cocoon-2.1-src/cocoon-2.1/src/webapp/samples/lassi/xsl/java-
pp.xsl_T-xslt-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/xsl/java-p.xsl_S-xml-1 (class: 
org.apache.cocoon.caching.CachedResponse) 

- Transformations applied
	java-oop.xsl

- Comment
Here everything still works ok, the process-map.xml has changed so the object 
ProcessMap is recreated out of it and stored in cache. Once more, ProcessMap 
returns the good steps and the right transformations have been applied. The 
result is cached correctly (entry 1).

----------------------------------
 Third Hit of java/test.xml after
 restoration of process-map.xml
 to its initial content
----------------------------------
- Process-map
I restore it to its initial state
	<relation from="java" to="oop"/>
	<relation from="oop" to="pp"/>
	<relation from="pp" to="p"/>

- MRUMemoryStore

	Same as after second hit (as expected)

- Transformations applied
	java-oop.xsl, oop-pp.xsl, pp-p.xsl

- Comment
Here, everything still works as expected, the StepManagerAction recreated the 
ProcessMap which returned the good steps and the right cache entry has been 
read from the store (note here that I don't know the exact behavior).

----------------------------------
 Conclusion of this first testcase
----------------------------------

Everything worked as expected, what's more it does so with any combination of 
modification to the process-map.xml provided that there is at least one 
transformation to be applied.

I will therefore give the results of the testcase when no transformation is 
applied.


--------------------------------------------------
 Erroneous testcase
--------------------------------------------------
First of all, I clear the store by hitting the page /samples/clearcache.html
This is exactly the same as in the first testcase until second hit, I will 
therefore start from that point:

----------------------------------
 Second Hit of java/test.xml after
 a modification of process-map.xml
----------------------------------
- Process-map
This time, I remove all lines, hence, no transformation should be applied.

- MRUMemoryStore

1 PK_G-file-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/process-map.xml_S-xml-1 (class: 
org.apache.cocoon.caching.CachedResponse) 

2 PK_G-file-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/process-map.xml (class: 
org.apache.cocoon.caching.CachedResponse) 

3 cocoon://samples/lassi/process-map.xml?pipelinehash=4251363787339917931 
(class: fr.eisti.lassi.elearning.cocoon.sitemap.ProcessMapEntry) 

4 PK_G-file-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/xml/java/javadoc.xml_S-xml-1 (class: 
org.apache.cocoon.caching.CachedResponse) 

5 PK_G-file-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/xml/java/javadoc.xml_T-xslt-file:/C:/TEMP/cocoon-
2.1-src/cocoon-2.1/src/webapp/samples/lassi/xsl/java-oop.xsl_T-xslt-
file:/C:/TEMP/cocoon-2.1-src/cocoon-2.1/src/webapp/samples/lassi/xsl/java-
pp.xsl_T-xslt-file:/C:/TEMP/cocoon-2.1-src/cocoon-
2.1/src/webapp/samples/lassi/xsl/java-p.xsl_S-xml-1 (class: 
org.apache.cocoon.caching.CachedResponse) 

- Comment
Everything still went fine, no transformations were applied as expected, and 
the right cache entry is created in store (entry 4).

----------------------------------
 Third Hit of java/test.xml after
 restoration of process-map.xml
 to its initial content
----------------------------------

- Process-map
I restore it to its initial state, hence all transformations should be applied.
	<relation from="java" to="oop"/>
	<relation from="oop" to="pp"/>
	<relation from="pp" to="p"/>

- MRUMemoryStore

	Same as after second hit (as expected)

- Comment
This time, the result is not the one expected !!! The action StepManagerAction 
recreated ProcessMap fine, it is stored in the cache, it returns the good steps 
(I have checked that by debugging) BUT the same result as in second hit is 
returned whereas it shoud return the same result as after the first hit.

----------------------------------
 Conclusion of this last testcase
----------------------------------

The result here is clearly not the one expected (at least by me ;)

The result is the one expected, when the Action returns at least one 
transformation to apply, ie the statements inside the Action are called at 
least once, but if it happens to return no transformations to be applied ( ie 
the statements inside the Action are not called), then, something goes wrong 
and even after modifying the process-map.xml so that transformations shoud be 
applied then cocoon keeps returning the cached entry which had no 
transformations applied.

What's more, the issue is also a matter of timing, because, as I was writing 
this mail, I waited a little while before hitting the page for the third time, 
and it returned the expected result, ie the same as after first hit. The 
erroneous behavior is obtained by hitting the pages without waiting too much 
between hits 2 and 3.

Thanks a lot for taking the time to read this mail. Please note that I am new 
to Actions and that I don't have a good knowledge of their impact on the 
pipeline and on caching so what I think to be a bug, may actually be a feature.

I would be really grateful, if you could give me your thoughts about that 
matter.


Cedric Vidal