<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">For us cancelling seems to work fine - although it seems like as soon as mondrian is done with SQL its not really possible to cancel the statement.<div>Do you check for cancel during segment processing? E.g. during each evaluation step of the tree?</div><div><br></div><div>I haven't done a full test to find out where it cancels and where it doesn't, it's just something I noticed in the past</div><div>Just my 2 cents on that topic.</div><div><br></div><div>-Paul<br><div><br></div><div><br><div><div>On Nov 19, 2013, at 5:37 PM, Luc Boudreau &lt;<a href="mailto:lucboudreau@gmail.com">lucboudreau@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hi Pedro,<div><br></div><div>Thanks for looking into this issue.</div><div><br></div><div>"<span style="font-family:arial,sans-serif;font-size:13px">Is it possible that we are trying to cancel the query when it's not ready to be stopped?</span>"</div>

<div><br></div><div>Possible. When we cancel the queries, we don't interrupt the thread, but we set a flag in Execution. We then check periodically, at certain checkpoints, the state of the cancelation flag and we break execution if needed. As far as I know, SleepUdf doesn't check that flag, so it won't be able to notice that the query was canceled.</div>

<div><br></div><div>Another situation where a cancelation won't happen is when two MDX queries try to access the same segment. If query 1 gets canceled, we check if other MDX statements need that particular segment and will only cancel it if nobody cares about it anymore.&nbsp;</div>

<div><br></div><div>It is also worth noting that we cannot enforce any kind of cancellation on the SQL drivers, other than calling cancel() and wishing for the best. Some drivers will return early, others will simply ignore the interruption flag on their thread (or whatever mechanism they use internally). This in turn blocks mondrian from checking the state of the MDX statement until the code returns from the driver.&nbsp;</div>

<div><br></div><div>Back to your scenario. It is possible that the field openCellSet is not assigned a value if you call cancel() from another thread right after you have created an MDX statement. We don't have a mechanism in there to 'cancel later'. Try adding an artificial delay between the time you create your statement and the time you call cancel and add some System.out calls into it to figure out in what order stuff happens. If this is the cause, we can probably fix that.</div>

<div><br></div><div>Lastly, if you see a spot in mondrian's code where the state of the execution should be checked but it isn't, please share your finding and we'll look into it.&nbsp;</div><div><br></div><div>Luc</div>

<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Nov 18, 2013 at 3:25 PM, Pedro Salgueiro <span dir="ltr">&lt;<a href="mailto:pedro.salgueiro@cortex-intelligence.com" target="_blank">pedro.salgueiro@cortex-intelligence.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hi,</span><div style="font-family:arial,sans-serif;font-size:13px">

<br></div><div style="font-family:arial,sans-serif;font-size:13px">I have been playing with the method Statement.cancel() in order to cancel some long running queries on user demand, which is not revealing to be an easy task.</div>


<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Although in some queries, the cancel() method seems to be working perfectly and an exception is thrown when the query is canceled, as it's supposed to be, on other queries, nothing happens.</div>


<div style="font-family:arial,sans-serif;font-size:13px">After some debugging, I reached to the conclusion that when a query includes many specific members, we are not able to cancel it.</div><div style="font-family:arial,sans-serif;font-size:13px">


<br></div><div style="font-family:arial,sans-serif;font-size:13px">If we execute the following query, we are able to cancel it with no problems.</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><blockquote class="gmail_quote" style="font-family:arial,sans-serif;font-size:13px;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


WITH&nbsp;<br>MEMBER [Measures].[Sleepy]<br>AS SleepUdf([Measures].[Unit Sales])</blockquote><blockquote class="gmail_quote" style="font-family:arial,sans-serif;font-size:13px;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


SELECT<br>[Product].[Product Family].Members ON 0,<br>[Measures].[Unit Sales],[Measures].[Sleepy] ON 1<br>FROM [Sales]</blockquote><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">


<br></div><div style="font-family:arial,sans-serif;font-size:13px">On the other hand, if we execute the following query with about 30 or 40 members, we are no longer able to cancel it:</div><div style="font-family:arial,sans-serif;font-size:13px">


<br></div><div style="font-family:arial,sans-serif;font-size:13px"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


WITH&nbsp;<br>MEMBER [Measures].[Sleepy]<br>AS SleepUdf([Measures].[Unit Sales])</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


SELECT<br>{[Product].[Product Family].[Member 1], [Product].[Product Family].[Member 1], ..., [Product].[Product Family].[Member n]} ON 0,</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


[Measures].[Unit Sales],[Measures].[Sleepy] ON 1<br>FROM [Sales]</blockquote><div><br></div><div>It's worth point out that SleepUdf is a user defined function which uses a Thread.sleep(), forcing the queries to take longer to execute, inspired by Mondrian's BasicQueryTest.java. This way we are able to properly test if the cancel is working.</div>


</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">I was looking at the cancel implementation in the MondrianOlap4jStatement class, and if the&nbsp;openCellSet is null, nothing is done. What are the conditions that would lead to a null openCellSet?&nbsp;</div>


<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">The queries that we are not being able to cancel produces a large number of SQL queries, and the cancel() method is executed while these SQL queries are being executed. Is it possible that we are trying to cancel the query when it's not ready to be stopped? Or maybethe cancel method encounters the query in a state that is not possible to be stopped yet, maybe between the execution of two SQL queries?</div>


<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">In situations like this, is there any other approach to cancel the query?</div><div style="font-family:arial,sans-serif;font-size:13px">


Do you know any easy solution to solve this problem?</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Any help will be greatly appreciated,</div>


<div style="font-family:arial,sans-serif;font-size:13px">Pedro Salgueiro</div></div>
<br>_______________________________________________<br>
Mondrian mailing list<br>
<a href="mailto:Mondrian@pentaho.org">Mondrian@pentaho.org</a><br>
<a href="http://lists.pentaho.org/mailman/listinfo/mondrian" target="_blank">http://lists.pentaho.org/mailman/listinfo/mondrian</a><br>
<br></blockquote></div><br></div>
_______________________________________________<br>Mondrian mailing list<br><a href="mailto:Mondrian@pentaho.org">Mondrian@pentaho.org</a><br>http://lists.pentaho.org/mailman/listinfo/mondrian<br></blockquote></div><br></div></div></body></html>