[classad-users] Problems with ClassAdCollections-Need help


Date: Fri, 16 Dec 2005 16:27:57 +0530
From: Imran Shaik <imran.sk@xxxxxxxxx>
Subject: [classad-users] Problems with ClassAdCollections-Need help
Hi ,
  I have a  problem now with my program using classads
  It is a  seg fault.
  I am attaching code,output and stack trace.Could you please tell me
where i have done the mistake.I was not able to find out.
  I get a seg fault in GetClassAd() method of ClassadCollection.For
one iteration it runs fine.But for another iteration same piece of
code seg faults.I couldnt find what went wrong.Can you pls help?

  Thanks in advance!!

Note:I am just attaching a simple code.

Regards,
Imran Shaik,
NIT Trichy-15
INDIA

Code
--------

#include<classad_distribution.h>
#include<iostream>
using namespace std;
#ifdef WANT_NAMESPACES
using namespace classad;
#endif
LocalCollectionQuery *lcq;
ClassAdCollection *cac;

string job_classad_text=

"["
"Type = \"Job\";"
"Id = 0;"
"Category=S;"
"Rank = other.KFlops/100 + other.Memory/32;"
"Requirements = true;"
"]";


int fillupClassAd(ClassAd* newad)
{

ClassAdUnParser unp;
ClassAdParser parser;
string   buffer;
PrettyPrint printer;
ClassAdIterator itr;
string          attrName;
const ExprTree  *attrExpr;

printer.Unparse(buffer,newad);
cout<<"fillupClassAd: ClassAd="<<buffer;

//ClassAd Fillup

cout<<"Enter Values for the new ClassAd"<<endl;
itr.Initialize(*newad);
char *attrExpression=new char[200];
ExprTree *expr;
while( !itr.IsAfterLast( ) ) {
        itr.CurrentAttribute( attrName, attrExpr );

		cout<<attrName<<"=";
		cin>>attrExpression;
		string newstringExpr(attrExpression);
		expr=parser.ParseExpression(newstringExpr);
		if(expr==NULL) cout<<"Expression parsing failed!!"<<endl;	
       	newad->Insert(attrName,expr);
        itr.NextAttribute( attrName, attrExpr );
}
}


int findMatch(ClassAd *jobad)
{
		
	PrettyPrint printer;
	ExprTree *expr;
	ClassAd *info;
	cac->GetViewInfo("resource",info);
	string infostrg;
	printer.Unparse(infostrg,info);
	cout<<"ViewInfo="<<infostrg<<endl;
	delete info;
	
	MatchClassAd  match_ad(jobad,NULL);
	
	bool qry_test=lcq->Query("resource");
	cout<<"qry_test="<<qry_test<<endl;
	
	lcq->ToFirst();
	string nextkey,currkey;
	int matchcount=0;
	ClassAd *cad1;
	while(!lcq->IsAfterLast())
	{
		lcq->Current(currkey);
		cout<<"Curent Key="<<currkey<<endl;
		
		cad1=cac->GetClassAd(currkey);
				
		if(cad1==NULL)
		{
		cout<<"findMatch,228:ClassAd not created,NULL returned"<<endl;
		cout<<"Reason:Out of memory or Emty collection"<<endl;
		}
		string cadstring;
		printer.Unparse(cadstring,cad1);
		
		match_ad.ReplaceRightAd(cad1);
		bool can_evaluate,ads_match;
		
		can_evaluate = match_ad.EvaluateAttrBool("rightMatchesLeft",ads_match);
		if(can_evaluate)
		{
			if(ads_match)
			{
			string classad_text;
			matchcount++;
			printer.Unparse(classad_text,cad1);
			cout<<"Matched Ad:"<<classad_text<<endl;
			cout<<"Sending match details to resource provider"<<endl;
			}
		}
			
	lcq->Next(nextkey);	
		
	}//while loop ends here
	
	if(matchcount==0)
	{
	cout<<"No match Found "<<endl;
	}
	lcq->ToAfterLast();
	//delete lcq;
}

int main()
{
	
	
	
	cac=new ClassAdCollection(false);
	if(cac==NULL)
	{
		cout<<"Match maker failed to initialise"<<endl;
		exit(0);
	}
	
	
	const string logfile="log.log";
	const string storefile="store.txt";
	const string chkptfile="chkpt.log";
	bool init_log=cac->InitializeFromLog(logfile,storefile,chkptfile);
	cout<<"init_log="<<init_log<<endl;
	lcq=new LocalCollectionQuery();
	if(lcq==NULL)
	{
		cout<<"LCQ_NULL"<<endl;
		exit(0);
	}
	lcq->Bind(cac);
	
	bool resourceview_create=cac->CreateSubView("resource", "root",
                           "other.Type==\"Machine\"","","");
	cout<<"resourceview_create="<<resourceview_create<<endl;
	
	ClassAdParser parser;
	ClassAd* jobad;
	for(int i=0;i<=10;i++)
	{
	jobad=parser.ParseClassAd(job_classad_text,true);
	//fillupClassAd(jobad);
	findMatch(jobad);
	}
		
	return 0;
}



output
---------


init_log=0
resourceview_create=0
ViewInfo=
    [
        Requirements = other.Type == "Machine";
        SubordinateViews =
           {
              "instrument",
              "visual",
              "store",
              "comp"
           };
        PartitionExprs =
           {
           };
        NumMembers = 5;
        Rank = undefined;
        PartitionedViews =
           {
           };
        ParentViewName = "root";
        ViewName = "resource"
    ]
qry_test=1
Curent Key=C77
Matched Ad:
    [
        Requirements = other.Type == "Job" && LoadAvg <
3.000000000000000E-01 && Memory - other.ImageSize >= 15;
        Id = 0;
        OpSys = "LINUX";
        LoadAvg = 4.296900000000000E-02;
        Mips = 104;
        IP = "127.0.0.1";
        Category = C;
        Memory = 64;
        Name = "silver.cs.nitt.edu";
        Arch = "INTEL";
        Rank = other.Owner == "csa0411" ? 1 : 0;
        Type = "Machine";
        KFlops = 21893
    ]
Sending match details to resource provider
Curent Key=V77
Matched Ad:
    [
        Requirements = other.Type == "Job" && LoadAvg <
3.000000000000000E-01 && Memory >= 40;
        Id = 0;
        OpSys = "LINUX";
        LoadAvg = 4.296900000000000E-02;
        Disk = 333;
        IP = "127.0.0.1";
        Category = V;
        Memory = 64;
        Arch = "INTEL";
        Rank = other.Owner == "csa0411" ? 1 : 0;
        Type = "Machine"
    ]
Sending match details to resource provider
Curent Key=S77
Matched Ad:
    [
        Requirements = other.Type == "Job" && LoadAvg <
3.000000000000000E-01 && Disk >= 40;
        Id = 0;
        OpSys = "LINUX";
        LoadAvg = 4.296900000000000E-02;
        Disk = 333;
        IP = "127.0.0.1";
        Category = S;
        Rank = other.Owner == "csa0411" ? 1 : 0;
        Type = "Machine"
    ]
Sending match details to resource provider
Curent Key=I77
Matched Ad:
    [
        Requirements = other.Type == "Job" && LoadAvg <
3.000000000000000E-01 && Disk >= 40;
        Id = 0;
        LoadAvg = 4.296900000000000E-02;
        IP = "127.0.0.1";
        Category = I;
        Memory = 64;
        Arch = "INTEL";
        Rank = other.Owner == "csa0411" ? 1 : 0;
        Type = "Machine"
    ]
Sending match details to resource provider
Curent Key=S87
Matched Ad:
    [
        Requirements = other.Type == "Job" && LoadAvg <
3.000000000000000E-01 && Disk >= 40;
        Id = 0;
        OpSys = "LINUX";
        LoadAvg = 4.296900000000000E-02;
        Disk = 333;
        IP = "127.0.0.1";
        Category = S;
        Rank = other.Owner == "csa0411" ? 1 : 0;
        Type = "Machine"
    ]
Sending match details to resource provider
ViewInfo=
    [
        Requirements = other.Type == "Machine";
        SubordinateViews =
           {
              "instrument",
              "visual",
              "store",
              "comp"
           };
        PartitionExprs =
           {
           };
        NumMembers = 5;
        Rank = undefined;
        PartitionedViews =
           {
           };
        ParentViewName = "root";
        ViewName = "resource"
    ]
qry_test=1
Curent Key=C77

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




stack trace
--------------------




Program received signal SIGSEGV, Segmentation fault.
0x08064b86 in ExprTree::SetParentScope (this=0x80e7770, scope=0x0) at
exprTree.C:73
73              _SetParentScope( scope );
(gdb) bt
#0  0x08064b86 in ExprTree::SetParentScope (this=0x80e7770, scope=0x0)
at exprTree.C:73
#1  0x0805c092 in ClassAdCollection::GetClassAd (this=0x80e3568,
key=@0xbfffecf0) at collectionBase.C:1300
#2  0x0804aea0 in findMatch (jobad=0x80f01b8) at matchtester.cc:81
#3  0x0804ba45 in main () at matchtester.cc:155








--
Yours,
Imran

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