Nested while loop weirdness

Post Reply
User avatar
Steve Rowe
Site Admin
Posts: 2455
Joined: Wed May 14, 2008 4:25 pm
OLAP Product: TM1
Version: TM1 v6,v7,v8,v9,v10,v11+PAW
Excel Version: Nearly all of them

Nested while loop weirdness

Post by Steve Rowe »

Ahh, there are time when I feel a deep pleasure at the power of TI and the debugging of the script.

Anyway I'm writing a TI to compare two versions of the same dimension which involves some nesting of while loops and I'm getting some odd behaviour.

The TI script in the prolog

Code: Select all

fileName=CellGetS( 'Server Properties', 'Server side path to dimension backup directory', 'String') | oldDimName | '.cma';

ixDim=1;
mxDim=DimSiz(dimName);
booFound=0;

#New elements in the current dimension structure
While (ixDim<=mxDim);
     elName=Dimnm(dimName, ixDim);

     If ( Dimix(oldDimName, elName)=0);
         ASCIIOutput( fileName, 'L’élément ' | elName | ' est présent dans la dimension courante mais pas dans n’existait pas dans la dimension histor
ique.', 'Type 1');
#List the structure relating to the new element.
#Parents
          ixPar=1;
          booParFound=0;
          mxPar=ElParN(dimName, elName);
#ASCIIOutput (fileName, str(mxPar,10,0));
          While(ixPar<=MxPar);
                 ASCIIOutput( fileName, 'L’élément ' | elName | ' a été rattaché a l’élément consolidé ' | Elpar (dimName, elName,ixPar),'Type 2');
                 ixPar=ixPar+1;
                 booParFound=1;
          End;
          If(booParFound=0);
                 ASCIIOutput( fileName, 'L’élément ' | elName | ' est un orphelin');
          EndIf;
#Children
          ixPar=1;
          booParFound=0;
          mxPar=ElCompN(dimName, elName);
#ASCIIOutput (fileName, str(mxPar,10,0));
          While(ixPar<=MxPar);
                 ASCIIOutput( fileName, 'Un nouvel élément ' | Elcomp (dimName, elName,ixPar) | ' a été rattaché a l’élément consolidé ' | elName | ' 
de la dimension ' ,'Type 3');
                 ixPar=ixPar+1;
                 booParFound=1;
          End;
          If(booParFound=0);
                 ASCIIOutput( fileName, 'L’élément ' | elName | ' has no children');
          EndIf;

     booFound=1;
     EndIf;
  ixDim=ixDim+1;
End;


If(booFound=0);
         ASCIIOutput( fileName, 'No new elements found','Type 4');
EndIf;

ASCIIOutput( fileName, 'Test sequence 1 complete' ,'Type check');

ProcessBreak;

Anyway as you can see it is all fairly fiddly, for the purposes of this post though everything within the while loops can be ignored.
Following the Process Break there are a few other sets of while loops that I have not shown.
I’ve been having a few issues with while loops locking up the server. In debugging this I added the process break and found that with the process break in place the while loops work. When I comment it out the while loops fail and the server locks.

My Ascii output with the break in place, you can see the final ASCIIoutput statement gets executed.

Code: Select all

"L’élément Element 24 est présent dans la dimension courante mais pas dans n’existait pas dans la dimension historique.","Type 1"
"L’élément Element 24 a été rattaché a l’élément consolidé Parent 3","Type 2"
"L’élément Element 24 has no children"
"L’élément Element 25 est présent dans la dimension courante mais pas dans n’existait pas dans la dimension historique.","Type 1"
"L’élément Element 25 a été rattaché a l’élément consolidé Parent 3","Type 2"
"L’élément Element 25 has no children"
"L’élément Element 26 est présent dans la dimension courante mais pas dans n’existait pas dans la dimension historique.","Type 1"
"L’élément Element 26 a été rattaché a l’élément consolidé Parent 3","Type 2"
"L’élément Element 26 has no children"
"L’élément Element 27 est présent dans la dimension courante mais pas dans n’existait pas dans la dimension historique.","Type 1"
"L’élément Element 27 a été rattaché a l’élément consolidé Parent 3","Type 2"
"L’élément Element 27 has no children"
"Test sequence 1 complete","Type check"
My Ascii output with the process break commented out, the last ASCII never gets executed and the server gets locked.

Code: Select all

"L’élément Element 24 est présent dans la dimension courante mais pas dans n’existait pas dans la dimension historique.","Type 1"
"L’élément Element 24 a été rattaché a l’élément consolidé Parent 3","Type 2"
"L’élément Element 24 has no children"
"L’élément Element 25 est présent dans la dimension courante mais pas dans n’existait pas dans la dimension historique.","Type 1"
"L’élément Element 25 a été rattaché a l’élément consolidé Parent 3","Type 2"
"L’élément Element 25 has no children"
"L’élément Element 26 est présent dans la dimension courante mais pas dans n’existait pas dans la dimension historique.","Type 1"
"L’élément Element 26 a été rattaché a l’élément consolidé Parent 3","Type 2"
"L’élément Element 26 has no children"
"L’élément Element 27 est présent dans la dimension courante mais pas dans n’existait pas dans la dimension historique.","Type 1"
"L’élément Element 27 a été rattaché a l’élément consolidé Parent 3","Type 2"
"L’élément Element 27 has no children" 
So for some unknown reason the main while loop is not finishing, unless I have the press break in place.

Anyone any idea what is going on??? All on version 9.0 latest.
Technical Director
www.infocat.co.uk
User avatar
Martin Ryan
Site Admin
Posts: 1989
Joined: Sat May 10, 2008 9:08 am
OLAP Product: TM1
Version: 10.1
Excel Version: 2010
Location: Wellington, New Zealand
Contact:

Re: Nested while loop weirdness

Post by Martin Ryan »

This is in the prolog, right? Is there anything in the metadata/data tabs? With metadata, it's not finalised until successful completion of the metadata tab. Perhaps there's something similar going on here? The final write is not going successfully because of an error further along.

Martin
Please do not send technical questions via private message or email. Post them in the forum where you'll probably get a faster reply, and everyone can benefit from the answers.
Jodi Ryan Family Lawyer
User avatar
Steve Rowe
Site Admin
Posts: 2455
Joined: Wed May 14, 2008 4:25 pm
OLAP Product: TM1
Version: TM1 v6,v7,v8,v9,v10,v11+PAW
Excel Version: Nearly all of them

Re: Nested while loop weirdness

Post by Steve Rowe »

Hi Martin, nothing in the other tabs.

The weirdness seems to be that the ProcessBreak seems to have an impact on the execution of prior lines of script.
I'm 99% sure that the logic on the indexes for the while loop is correct (since it works with Process Break in place), it's only after I remove the Process Break that everything goes pear shaped, and it goes pear shaped before the process break since I can see that the "ASCIIOutput( fileName, 'Test sequence 1 complete' ,'Type check');" never gets executed.
Stumped!
Technical Director
www.infocat.co.uk
User avatar
Martin Ryan
Site Admin
Posts: 1989
Joined: Sat May 10, 2008 9:08 am
OLAP Product: TM1
Version: 10.1
Excel Version: 2010
Location: Wellington, New Zealand
Contact:

Re: Nested while loop weirdness

Post by Martin Ryan »

Very peculiar. What happens if you delete all the code within the while loop? If that fixes it, can you add stuff back line by line to see who is the culprit? Though I don't see anything that might impact it. The only thing I can think of is that the "fileName" variable changes somehow, but that looks impossible.

Failing that, what about adding another random asciioutput line. I guess it's possible that TM1 doesn't finish writing to the ascii file, but the processbreak gives it time to tie up the loose ends.

Neither of those are very good ideas, but that's a really weird problem!
Please do not send technical questions via private message or email. Post them in the forum where you'll probably get a faster reply, and everyone can benefit from the answers.
Jodi Ryan Family Lawyer
User avatar
Steve Rowe
Site Admin
Posts: 2455
Joined: Wed May 14, 2008 4:25 pm
OLAP Product: TM1
Version: TM1 v6,v7,v8,v9,v10,v11+PAW
Excel Version: Nearly all of them

Re: Nested while loop weirdness

Post by Steve Rowe »

Just an update on this since I found the problem.

One of the while loops after the process break (not shown in the OP) was not indexed correctly and should have casued that while loop to get stuck in an infinite loop. Once I fixed this the TI behaves as exepcted.

The very strange thing is that the TI seemed to bug out in the wrong place if you go according to what ASCII statements the TI was able to spit out, anyway don't have the time for a proper investigation....

Cheers
Technical Director
www.infocat.co.uk
hbell
Posts: 61
Joined: Wed Feb 25, 2009 6:15 pm
Version: 9.1 SP3
Excel Version: 11.8

Re: Nested while loop weirdness

Post by hbell »

We've experienced something very similar. We have had processes that seem somehow to "uncommit" earlier actions if a later action fails. It is a devil to debug and I've been unable to identify the conditions where it happens though all the processes in my direct experience were ones with no data processing content - just Prolog and Epilog.

hugh
User avatar
paulsimon
MVP
Posts: 808
Joined: Sat Sep 03, 2011 11:10 pm
OLAP Product: TM1
Version: PA 2.0.5
Excel Version: 2016
Contact:

Re: Nested while loop weirdness

Post by paulsimon »

Steve

One thing I have done a few times to get past problems like this is to put a get out clause in to the while loop along the lines of if fileexists then processquit. Then I just drop a file called HALT in to the cube directory and that makes the while loop jump out. Otherwise the only way out is usually to kill the server as most of the time TM1 Top won't stop a process that is in an endless while loop. Obviously if all the indexes and conditions are perfect this isn't necessary and it is an overhead, but it can be handy when debugging.

Regards


Paul Simon
User avatar
Steve Rowe
Site Admin
Posts: 2455
Joined: Wed May 14, 2008 4:25 pm
OLAP Product: TM1
Version: TM1 v6,v7,v8,v9,v10,v11+PAW
Excel Version: Nearly all of them

Re: Nested while loop weirdness

Post by Steve Rowe »

Thanks for the tip Simon, that's a good one.
Technical Director
www.infocat.co.uk
Post Reply