Exemplo n.º 1
0
static inline NsEventWriter *createWriter(XmlDocument &xdoc,
					  const DynamicContext *context,
					  NsFullNid *rootNid)
{
	XmlManager &mgr = GET_CONFIGURATION(context)->getManager();
	xdoc = mgr.createDocument();
	
	// prepare to create NsEventWriter
	DictionaryDatabase * dict = ((Manager&)mgr).getDictionary();
	CacheDatabaseMinder &dbMinder = GET_CONFIGURATION(context)->
		getDbMinder();
	// get the temp DB for construction (container id 0)
	CacheDatabase *cdb = dbMinder.findOrAllocate((Manager&)mgr, 0);
	DocID did = dbMinder.allocateDocID((Manager&)mgr);

	// Tell the document to use this database, and that it's
	// content is "NsDom"
	// TBD GMF: Eventually it may be that Document and NsDocument objects 
	// will not be required by DbXmlNodeImpl, so creation/init of Document
	// objects will not be required.
	((Document&)xdoc).setContentAsNsDom(did, cdb);

	NsEventWriter *writer = new NsEventWriter(cdb->getDb(), dict, did);
	writer->writeStartDocumentInternal(0, 0, 0, rootNid);
	return writer;
}
Exemplo n.º 2
0
void ResultsEventWriter::createEventWriter(void)
{
	DBXML_ASSERT(depth_ == 0);
	DBXML_ASSERT(!writer_);
	DBXML_ASSERT(!xmlDoc_);

	// prepare to create NsEventWriter
	XmlManager& mgr = res_->getManager();
	CacheDatabaseMinder& dbMinder = res_->getDbMinder();
	xmlDoc_ = mgr.createDocument();

	// allocate a DocID
	DocID did = dbMinder.allocateDocID((Manager&)mgr);

	// get the temp DB for construction (container id 0)
	CacheDatabase *cdb = dbMinder.findOrAllocate((Manager&)mgr, 0);

	// Tell the document to use this database, and that it's
	// content is "NsDom"
	// TBD GMF: Eventually it may be that Document and NsDocument objects
	// will not be required by DbXmlNodeImpl, so creation/init of Document
	// objects will not be required.
	DictionaryDatabase *dict = ((Manager&)mgr).getDictionary();
	((Document&)xmlDoc_).setContentAsNsDom(did, cdb);

	writer_ = new NsEventWriter(cdb->getDb(), dict, did);
	writer_->writeStartDocument(version_, encoding_, standalone_);

	DBXML_ASSERT(writer_);
	DBXML_ASSERT(xmlDoc_);
}
Exemplo n.º 3
0
DbWrapper *ContainerBase::getDbWrapper(DynamicContext *context) {
	if (context) {
		CacheDatabaseMinder &dbMinder =
			GET_CONFIGURATION(context)->
			getDbMinder();
		if (!dbMinder.isNull()) {
			CacheDatabase *cdb =
				dbMinder.findOrAllocate(
				mgr_, getContainerID());
			if (cdb)
				return cdb->getDb();
		}
	}
	return 0;
}
Exemplo n.º 4
0
void simpleTestCacheDatabase1( CacheDatabase& cache_db, ContextManager cm )
{
	/*ConfigParametersV cp;
	ConfigurationLoader config;
	config.loadVConfigFile( "V_test_cache.xml", cp );

	CacheDatabase cache_db;

	setupMemEnv( cp );

	cache_db.Initialize( memEnv, cp );*/

	ContextStructure* c_struct, *c_struct2;
	//ContextManager cm(1,1,4);
	cm.GetFreeContext( c_struct );
	cm.GetFreeContext( c_struct2 );

	CacheKey cacheKey( c_struct );
	CacheValue cacheValue( c_struct ), CacheRetrieveVal( c_struct2 );

	string strDzName = "testCacheDz", strKey = "testCacheKey";
	Vdt dzName = TCUtility::convertToVdt( strDzName );
	Vdt key = TCUtility::convertToVdt( strKey );

	int bufsize = 1024;
	char bufVal[1024];
	char bufValres[1024];
	char data[] = "121212";
	memcpy(&bufVal, &data, 7); 

	LARGE_INTEGER timestamp;
	QueryPerformanceCounter( &timestamp );

	cacheKey.setValues(dzName, key );
	cacheValue.setDataRecValues( &bufVal, bufsize );
	CacheRetrieveVal.setDataRecValues( &bufValres, 1024 );

	if( cache_db.InsertDataRec( cacheKey, cacheValue, 0 ) != 0 )
		cout<< "Error. Could not insert\n";

	if( cache_db.GetDataRec( cacheKey, CacheRetrieveVal, 0 ) != 0 )
		cout<< "Error. Could not get\n";

	//get Data_rec value from Cache
	void* data_p; 
	char* rvalue;
	int rsize = 0;
	CacheRetrieveVal.getDataRec(data_p, rsize);
	rvalue = (char*)data_p;

	//Set MD values to insert in Cache
	char dirtybit = '1';
	double qval = (double)1/1024;
	cacheKey.setValues(dzName, key );
	cacheValue.setMDValues( dirtybit, qval );
	//CacheRetrieveVal.setMDValues( &bufValres, bufsize );

	if( cache_db.InsertMDLookup( cacheKey, cacheValue, 0 ) != 0 )
		cout<< "Error. Could not insert\n";

	if( cache_db.GetMDLookup( cacheKey, CacheRetrieveVal, 0 ) != 0 )
		cout<< "Error. Could not get\n";

	//get MD values value from Cache
	char dirty = CacheRetrieveVal.getDirtyBit();
	//res += sizeof(dirty);
	TCQValue qback = CacheRetrieveVal.getQValue();

	cacheKey.setValues(dzName, key );
	if( cache_db.DeleteDataRec( cacheKey, 0 ) != 0 )
		cout<< "Error. Could not delete\n";

	if( cache_db.GetDataRec( cacheKey, CacheRetrieveVal, 0 ) == 0 )
		cout<< "Error. Deleted record was found\n";

	
	cacheKey.setValues( dzName, key );
	if( cache_db.DeleteMDLookup( cacheKey, 0 ) != 0 )
		cout<< "Error. Could not delete\n";

	if( cache_db.GetMDLookup( cacheKey, CacheRetrieveVal, 0 ) == 0 )
		cout<< "Error. Deleted record was found\n";

	cache_db.Shutdown();

	cm.ReleaseContext( c_struct );
	cm.ReleaseContext( c_struct2 );

	//return -1;
}
Exemplo n.º 5
0
void testCacheDbLoop1(CacheDatabase& cache_db, ContextManager cm, ConfigParametersV cp )
{
	int num_ofrecords = 1000000000;
	int number_of_partitions = cp.MemBDB.DatabaseConfigs.Partitions;
	LARGE_INTEGER begin, end, num_ticks;
	QueryPerformanceFrequency( &num_ticks );

	ContextStructure* c_struct, *c_struct2;
	cm.GetFreeContext( c_struct );
	cm.GetFreeContext( c_struct2 );

	CacheKey cacheKey( c_struct );
	CacheValue cacheValue( c_struct ), CacheRetrieveVal( c_struct2 );

	string strDzSeedName = "testLoopDz", strKey = "testLoopKey", strValue = "testLoopValue";
	Vdt dzName, key, Value; // = TCUtility::convertToVdt( strDzName );
	string sDZName, sKey, sValue;

	
	int partition_number;
	int dataRec_inserted = 0, dataRec_retrieved = 0;
	int md_inserted = 0, md_retrieved = 0;
	int dataRec_deleted = 0, md_deleted = 0;
	TCQValue qval(0,0.0);
	char dirtybit = '1';
	char cleanbit = '0';
	bool quitloop = false;
	char* dataBuf = new char[sizeof_rec_in1];
	
	std::cout << "Inserting records in Cache..." << std::endl;

	QueryPerformanceCounter( &begin );
	for(int i = 1; i < num_ofrecords && !quitloop; i++)
	{			
		sDZName = strDzSeedName + TCUtility::intToString(i);
		dzName = TCUtility::convertToVdt( sDZName );
		sKey = strKey + TCUtility::intToString(i);
		key = TCUtility::convertToVdt( sKey );
		
		sValue = strValue + TCUtility::intToString(i);
		memcpy(dataBuf, (char*)sValue.c_str(), sValue.length());
		Value.set_data(dataBuf);
		Value.set_size(sizeof_rec_in1);
		//Value = TCUtility::convertToVdt( sValue );

		cacheKey.setValues( dzName, key );
		cacheValue.setDataRecValues( Value );

		partition_number = i % number_of_partitions;
		if( cache_db.InsertDataRec( cacheKey, cacheValue, partition_number) == 0 )
			dataRec_inserted++;
		else
		{
			std::cout << "Cache Data_rec is full" << std::endl;
			quitloop = true;
		}

		qval = (double)1 / (i * number_of_partitions);
		
		if(i/num_ofrecords == 0)
			cacheValue.setMDValues( dirtybit, qval );
		else
			cacheValue.setMDValues( cleanbit, qval );

		if( cache_db.InsertMDLookup( cacheKey, cacheValue, partition_number) == 0 )
			md_inserted++;
		else
		{
			std::cout << "Cache MD is full" << std::endl;
			quitloop = true;
		}
	}
	QueryPerformanceCounter( &end );
	cout << "Records Inserted in DataRec: " << dataRec_inserted << std::endl;
	cout << "Records Inserted in MD: " << md_inserted << std::endl;
	cout << "Time taken (seg): " << (double)(end.QuadPart - begin.QuadPart) / num_ticks.QuadPart << std::endl << std::endl;
	delete [] dataBuf;
	dataBuf = NULL;


	string sDZName2, sKey2;
	dataBuf = new char[sizeof_rec_out1];
	qval.setFraction(0.0);
	qval.setInt(0);
	TCQValue qvalr(0,0.0);
	quitloop = false;
	std::cout << "Retriving records from Cache..." << std::endl;
	char bit;
	string datar;
	
	QueryPerformanceCounter( &begin );
	for(int i = 1; i < num_ofrecords && !quitloop; i++)
	{
		sDZName2 = strDzSeedName + TCUtility::intToString(i);
		dzName = TCUtility::convertToVdt( sDZName2 );
		sKey2 = strKey + TCUtility::intToString(i);
		key = TCUtility::convertToVdt( sKey2 );
		
		sValue = strValue + TCUtility::intToString(i);
		
		Value.set_data(dataBuf);
		Value.set_size(sizeof_rec_out1);
		
		cacheKey.setValues( dzName, key );
		CacheRetrieveVal.setDataRecValues( Value );

		partition_number = i % number_of_partitions;
		if( cache_db.GetDataRec( cacheKey, CacheRetrieveVal, partition_number) == 0 )
			dataRec_retrieved++;
		else
		{
			std::cout << "Records in Data_rec not Found" << std::endl;
			quitloop = true;
			break;
		}

		datar.clear();
		datar.insert(0, (char*)Value.get_data(), sValue.length());
		if(sValue.compare(datar) != 0)
			std::cout << "Record's value in Data_rec don't match" << std::endl;

		qval.setFraction( (double)1 / (i * number_of_partitions) );
		if( cache_db.GetMDLookup( cacheKey, CacheRetrieveVal, partition_number) == 0 )
			md_retrieved++;
		else
		{
			std::cout << "Records in MD not Found" << std::endl;
			quitloop = true;
			break;
		}
		qvalr = CacheRetrieveVal.getQValue();
		if(qval != qvalr)
			std::cout << "Wrong Qval Found" << std::endl;

		bit = CacheRetrieveVal.getDirtyBit();
		if(i/num_ofrecords == 0)
			dirtybit = '1';
		else
			dirtybit = '0';

		if(bit != dirtybit)
			std::cout << "Wrong DirtyBit Found" << std::endl;

	}
	QueryPerformanceCounter( &end );

	cout << "Records retrieved from DataRec: " << dataRec_retrieved << std::endl;
	cout << "Records retrieved from MD: " << md_retrieved << std::endl;
	cout << "Time taken (seg): " << (double)(end.QuadPart - begin.QuadPart) / num_ticks.QuadPart  << std::endl << std::endl;
	delete [] dataBuf;
	dataBuf = NULL;


	qval = 0.0;
	quitloop = false;
	//Deletes records
	QueryPerformanceCounter( &begin );
	for(int i = 1; i < num_ofrecords && !quitloop ; i++)
	{
		sDZName2 = strDzSeedName + TCUtility::intToString(i);
		dzName = TCUtility::convertToVdt( sDZName2 );
		sKey2 = strKey + TCUtility::intToString(i);
		key = TCUtility::convertToVdt( sKey2 );

		cacheKey.setValues( dzName, key );

		partition_number = i % number_of_partitions;
		if( cache_db.DeleteDataRec( cacheKey, partition_number) == 0 )
			dataRec_deleted++;
		else
		{
			std::cout << "Records in Data_rec not deleted" << std::endl;
			quitloop = true;
			break;
		}

		qval = (double)1 / (i * number_of_partitions);
		if( cache_db.DeleteMDLookup( cacheKey, partition_number) == 0 )
			md_deleted++;
		else
		{
			std::cout << "Records in MD not deleted" << std::endl;
			quitloop = true;
			break;
		}

	}

	QueryPerformanceCounter( &end );

	cout << "Records deleted from Data_Rec: " << dataRec_deleted << std::endl;
	cout << "Records deleted from MD: " << md_deleted << std::endl;
	cout << "Time taken (seg): " << (double)(end.QuadPart - begin.QuadPart) / num_ticks.QuadPart  << std::endl;

	cm.ReleaseContext( c_struct );
	cm.ReleaseContext( c_struct2 );
	
}