[classad-users] ClassAdCollections and InitialisefromLog


Date: Tue, 6 Dec 2005 03:21:27 +0530
From: Imran Shaik <imran.sk@xxxxxxxxx>
Subject: [classad-users] ClassAdCollections and InitialisefromLog
Hi Alain,
 I am attaching the source code with output.


 source code
 -------------------
#include <classad_distribution.h>
#include <iostream>

using namespace std;
#ifdef WANT_NAMESPACES
using namespace classad;
#endif

string job_classad_text =
"["
"Requirements = (other.Type == \"Machine\" && other.memory >= 4000);"
"Type = \"Job\";"
"Memoryused = 6000;"
"Rank = 2;"
"]";

string machine_classad_text =
"["
"Type = \"machine\";"
"Requirements = (other.Type == \"job\" && other.Memoryused < 8000);"
"Memory = 6500;"
"Rank = Memory/3000;"
"]";

string machine_classad_text1 =
"["
"Type = \"machine\";"
"Requirements = (other.Type == \"job\" && other.Memoryused < 7000);"
"Memory = 5900;"
"Rank = Memory/2000;"
"]";


string machine_classad_text2 =
"["
"Type = \"machine\";"
"Requirements = (other.Type == \"job\" && other.Memoryused < 5000);"
"Memory = 8000;"
"Rank = Memory/2000;"
"]";


string machine_classad_text3 =
"["
"Type = \"machine\";"
"Requirements = (other.Type == \"job\" && other.Memoryused < 4000);"
"Memory = 6000;"
"Rank = Memory/600;"
"]";

string machine_classad_text4 =
"["
"Type = \"machine\";"
"Requirements = (other.Type == \"job\" && other.Memoryused < 3000);"
"Memory = 5500;"
"Rank = Memory/110;"
"]";


int main(int argc, char *argv)
{

               ClassAdParser  parser;
       ClassAd   *jad,*mad0,*mad1,*mad2,*mad3,*mad4;
       jad     = parser.ParseClassAd(job_classad_text, true);
       mad0 = parser.ParseClassAd(machine_classad_text, true);
       mad1 = parser.ParseClassAd(machine_classad_text1, true);
       mad2 = parser.ParseClassAd(machine_classad_text2, true);
       mad3 = parser.ParseClassAd(machine_classad_text3, true);
       mad4 = parser.ParseClassAd(machine_classad_text4, true);


       PrettyPrint  printer;



       ClassAdCollection *cac=new ClassAdCollection(true);
       bool init_log;
       const string filename="/home/csa0411/mylog.log";
       const string chkptfilename="/home/csa0411/chkpt.log";
       const string storagefile="/home/csa0411/store.txt";
       init_log=cac->InitializeFromLog(filename,storagefile,chkptfilename);
       cout<<"init_log="<<init_log<<endl;


       bool add_classad=cac->AddClassAd("C0",mad0);
       cout<<"add_classad="<<add_classad<<"C0 Added"<<endl;

       add_classad=cac->AddClassAd("C1",mad1);
       cout<<"add_classad="<<add_classad<<"C1 Added"<<endl;

       add_classad=cac->AddClassAd("C2",mad2);
       cout<<"add_classad="<<add_classad<<"C2 Added"<<endl;
       add_classad=cac->AddClassAd("V1",mad3);
       cout<<"add_classad="<<add_classad<<"V1 Added"<<endl;
       add_classad=cac->AddClassAd("J1",jad);
       cout<<"add_classad="<<add_classad<<"J1 Added"<<endl;

       add_classad=cac->AddClassAd("C3",mad2);
       cout<<"add_classad="<<add_classad<<"C3 Added"<<endl;

       /*cout<<"Add Another ClassAd"<<endl;
       add_classad=cac->AddClassAd("C4",mad4);
       cout<<"add_classad="<<add_classad<<"C4 added"<<endl;*/


       cout<<"*****************************************"<<endl;
       cout<<"CHECK FOR CLASSADS IN THE COLLECTION"<<endl;

       ClassAd *ad;
       ad=cac->GetClassAd("C0");
       if(ad==mad0)
               cout<<"classad C0 is present in collection"<<endl;
       else cout<<"classad C0 is NOT present in collection"<<endl;
       ad=cac->GetClassAd("C1");
       if(ad==mad1)
               cout<<"classad C1 is present collection"<<endl;
       else cout<<"classad C1 is NOT present in collection"<<endl;
       ad=cac->GetClassAd("C2");
       if(ad==mad2)
               cout<<"classad C2 is present collection"<<endl;
       else cout<<"classad C2 is NOT present in collection"<<endl;

       ad=cac->GetClassAd("C3");
       if(ad==mad2)
               cout<<"classad C3 is present collection"<<endl;
       else cout<<"classad C3 is NOT present in collection"<<endl;

       ad=cac->GetClassAd("V1");
       if(ad==mad3)
               cout<<"classad V1 is present collection"<<endl;
       else cout<<"classad V1 is NOT present in collection"<<endl;
       ad=cac->GetClassAd("J1");
       if(ad==jad)
               cout<<"classad J1 is present collection"<<endl;
       else cout<<"classad J1 is NOT present in collection"<<endl;

       cout<<"****************************************"<<endl;

       cout<<"CREATE A SIMPLE VIEW"<<endl;

       bool view_create=cac->CreateSubView("resource", "root",
                          "","","");

       cout<<"view_create="<<view_create<<"Resource View Created"<<endl;






       cout<<"***************************************"<<endl;
       cout<<"DISPLAY VIEW INFO"<<endl;
       ClassAd *c=new ClassAd();
       cac->GetViewInfo("resource",c);
       string strg1;
       printer.Unparse(strg1,c);
       cout<<"ViewInfo="<<strg1<<endl;
       delete c;

       cout<<"***************************************"<<endl;
       //cout<<"program was receiving seg fault here"<<endl;

       LocalCollectionQuery *lcq=new LocalCollectionQuery();
       lcq->Bind(cac);


       ExprTree *expr;
       expr=parser.ParseExpression("other.Memory<=6500");
       bool lcq_test=lcq->Query("resource",expr);
       string currkey;
       cout<<"............................................."<<endl;

       lcq->ToFirst();

       string nextkey;

       while(!lcq->IsAfterLast())
       {
               lcq->Current(currkey);
               cout<<"Curent Key="<<currkey<<endl;
               string classad_text;
               ClassAd *cad=cac->GetClassAd(currkey);
               printer.Unparse(classad_text,cad);
               cout<<classad_text<<endl;
               lcq->Next(nextkey);

       }
       //cout<<"Program was segfaulting here"<<endl;
       cac->TruncateLog();
       cac->TruncateStorageFile();
       delete cac;

               return 0;

}


output
---------

EXECUTING:
/home/csa0411/Mygrid/ForAlainRoy/segfltcollection2
----------------------------------------------
init_log=1
add_classad=1C0 Added
add_classad=1C1 Added
add_classad=1C2 Added
add_classad=1V1 Added
add_classad=1J1 Added
add_classad=1C3 Added
*****************************************
CHECK FOR CLASSADS IN THE COLLECTION
classad C0 is present in collection
classad C1 is NOT present in collection
classad C2 is NOT present in collection
classad C3 is present collection
classad V1 is present collection
classad J1 is present collection
****************************************
CREATE A SIMPLE VIEW
view_create=1Resource View Created
Add Another ClassAd
add_classad=1C4 added
***************************************
DISPLAY VIEW INFO
ViewInfo=
   [
       Requirements = true;
       SubordinateViews =
          {
          };
       PartitionExprs =
          {
          };
       NumMembers = 9;
       Rank = undefined;
       PartitionedViews =
          {
          };
       ParentViewName = "root";
       ViewName = "resource"
   ]
***************************************
.............................................
Curent Key=C0

   [
       Requirements = ( other.Type == "job" && other.Memoryused < 8000 );
       Memory = 6500;
       Rank = Memory / 3000;
       Type = "machine"
   ]
Curent Key=C0

   [
       Requirements = ( other.Type == "job" && other.Memoryused < 8000 );
       Memory = 6500;
       Rank = Memory / 3000;
       Type = "machine"
   ]
Curent Key=C1

   [
       Requirements = ( other.Type == "job" && other.Memoryused < 7000 );
       Memory = 5900;
       Rank = Memory / 2000;
       Type = "machine"
   ]
Curent Key=V1

   [
       Requirements = ( other.Type == "job" && other.Memoryused < 4000 );
       Memory = 6000;
       Rank = Memory / 600;
       Type = "machine"
   ]
Curent Key=C4

   [
       Requirements = ( other.Type == "job" && other.Memoryused < 3000 );
       Memory = 5500;
       Rank = Memory / 110;
       Type = "machine"
   ]

----------------------------------------------
Program has been terminated receiving signal 11 (Segmentation fault)
Press the Enter key to close this terminal ...



output2  (when i remove comments around addition of classad mad4 with key C4)
-----------

EXECUTING:
/home/csa0411/Mygrid/ForAlainRoy/segfltcollection2
----------------------------------------------
init_log=1
add_classad=1C0 Added
add_classad=1C1 Added
add_classad=1C2 Added
add_classad=1V1 Added
add_classad=1J1 Added
add_classad=1C3 Added
*****************************************
CHECK FOR CLASSADS IN THE COLLECTION
classad C0 is NOT present in collection
classad C1 is present collection
classad C2 is NOT present in collection

----------------------------------------------
Program has been terminated receiving signal 11 (Segmentation fault)
Press the Enter key to close this terminal ...




I know its a big mail.But i wanted to give clear idea of whats
happening.So i copied sample source code and output.I dont understand
what mistake i am doing .Pls help me out.


Regards,
Imran


























On 11/26/05, Alain Roy <roy@xxxxxxxxxxx> wrote:
>
> >   I meant ClassAdCollectionServer and Client classes ,I wrote as
> >LocalCollectionServer by mistake taking half from actual name and the
> >other from LocalCollectionQuery.I am sorry!!
>
> The server and client are not distributed with ClassAds, sorry. They
> haven't been touched in years, and they rely in lots of external Condor
> libraries.
>
> >  1.I add classAds to collection say about 9 to 10 continuosly,without
> >removing any in between.I face a segmentation fault when i read the
> >log again with InitialiseFromLog(). Is the number of classAds that can
> >be added to the collection limited to 5(I remember of max cache size
> >or some member like max classads).
>
> No, definitely not. We've had people with hundreds or thousands of ClassAds
> in a collection.
>
> Without details like a stack trace, it's hard to say what the problem is.
>
> >Or can u tell me the maximum number of classads a collection can
> >hold?If there is restriction on MaxClassAds a collection hold,then how
> >can i flush the cache?
>
> There is no particular limit. I don't know what you mean by flushing the
> cache. The caching code isn't well tested, so it may be your problem.
>
> >If How much memory is allocated for a typical collection.?
>
> As much as is needed.
>
> >If it replays during InitialiseFromLog() ,is that actually causing seg fault?
>
> Without seeing the seg fault, I can't say. The source code would probably
> be useful too.
>
> >2.Also when i set cache to false and keep on adding classads to
> >collection, and finally delete the pointer to collection i get a seg
> >fault.When i comment that pointer deletion line,things work fine.Can u
> >say whats happening ?Am i wrong somewhere?
> >
> >For example
> >------------------
> >ClassAdCollection *cac=new ClassAdCollection(false);
> >cac->InitialiseFromLog(logfilename);
> >cac->AddClassAd(ad1);
> >cac->AddClassAd(ad2);
> >.
> >.
> >.
> >cac->AddClassAd(ad7);
> >delete cac;  //if i remove this line it wont segfault,else it segfaults
>
> Are you deleting the ClassAds individually?
>
> >4.I see only very few questions  posted in 2005 in the classad-user
> >group.Why so?
>
> I don't know why.
>
> -alain
>
>
> Condor Classads Info:
> http://www.cs.wisc.edu/condor/classad/
>


--
Yours,
Imran


--
Yours,
Imran

[← Prev in Thread] Current Thread [Next in Thread→]