Esempio n. 1
0
/*
 * Setup file name and path
 */
void	CDBDeltaFile::setup(const std::string& name, const std::string& path, uint32 rowSize, const CTimestamp& startTimestamp, const CTimestamp& endTimestamp)
{
	uint32		tableId;
	CTimestamp	timestamp;
	nlassert(isDeltaFileName(name, tableId, timestamp));

	_Name = name;
	_Path = NLMISC::CPath::standardizePath(path);

	_Header.RowSize = rowSize;
	_Header.FullRowSize = rowSize + getRowHeaderSize();
	//_Header.Timestamp = timestamp.toTime();
	_Header.StartTimestamp = uint32(startTimestamp.toTime());
	_Header.EndTimestamp = uint32(endTimestamp.toTime());
}
Esempio n. 2
0
/*
 * Update
 * Call regularly this method once a tick to apply changes to database
 */
void	CPDSLib::update()
{
	if (_UsePDS)
	{
		// check pds is ready to receive update
		if (!PDSReady())
			return;

		if (_DbMessageQueue.empty())
			return;

		std::list<CDbMessageQueue>::iterator	it;
		for (it=_DbMessageQueue.begin(); it!=_DbMessageQueue.end(); ++it)
		{
			CDbMessageQueue&	queue = (*it);

			// create a new message
			CMessage*	msgupd = new CMessage("PD_UPDATE");
			msgupd->serial(_DatabaseId);
			msgupd->serial(_UpdateId);
			_QueuedMessages.push_back(make_pair<uint32,CMessage*>(_UpdateId, msgupd));
			++_UpdateId;

			// serial queue
			msgupd->serial(queue);

			// send update to the pds
			CUnifiedNetwork::getInstance()->send("PDS", *msgupd);
		}

		// clean up for next update
		_DbMessageQueue.clear();
	}
	else
	{
		uint	i;

		// save log (updates + string manager)
		TTime	ctime = CTime::getLocalTime();

		//
		CTimestamp	timestamp;
		timestamp.setToCurrent();

		// setup update logs with full timestamp
		if (!_DbMessageQueue.empty())
		{
			i = (uint)_UpdateLogs.size();
			_UpdateLogs.resize(_DbMessageQueue.size());

			for (; i<_UpdateLogs.size(); ++i)
			{
				_UpdateLogs[i].StartStamp = _PreviousTickDate;
				_UpdateLogs[i].EndStamp = _PreviousTickDate;
			}

			_UpdateLogs.back().EndStamp = timestamp;
		}

		_PreviousTickDate = timestamp;

		if (ctime - _PreviousLogSave > PDLogUpdate*1000 && !_DbMessageQueue.empty())
		{
//			std::string	logDir = getRemoteLogDirectory();
//			std::string	logFile = _LogStartDate.toString()+"_0000.pd_log";
//
//			// if don't use BS, create logdir directory tree
//			if (!PDUseBS && !CFile::isDirectory(logDir))
//			{
//				if (!CFile::createDirectoryTree(logDir))
//				{
//					nlwarning("Failed to create log root directory '%s'", logDir.c_str());
//				}
//
//				if (!CFile::setRWAccess(logDir))
//				{
//					nlwarning("Failed, can't set RW access to directory '%s'", logDir.c_str());
//				}
//			}
//
//			// map update logs to msg queues
//			nlassert(_UpdateLogs.size() == _DbMessageQueue.size());
//			for (i=0; i<_UpdateLogs.size(); ++i)
//				_UpdateLogs[i].setUpdates(&(_DbMessageQueue.get(i)));
//
//			if (PDUseBS)
//			{
//				CBackupMsgSaveFile	msgBS( logDir+logFile, CBackupMsgSaveFile::AppendFileCheck, PDBsi );
//				msgBS.DataMsg.serialCont(_UpdateLogs);
//				PDBsi.append(msgBS);
//			}
//			else
//			{
//				COFile				file;
//				if (file.open(logDir + logFile))
//				{
//					file.serialCont(_UpdateLogs);
//				}
//				else
//				{
//					nlwarning("Failed to save log file '%s' for database %d", (logDir + logFile).c_str(), _DatabaseId);
//				}
//			}

//			if (PDEnableStringLog && !_StringManager.logEmpty())
//			{
//				std::string			logFile = timestamp.toString()+".string_log";
//
//				if (PDUseBS)
//				{
//					bool				success = false;
//					CBackupMsgSaveFile	msgBS( logDir+logFile, CBackupMsgSaveFile::SaveFileCheck, PDBsi );
//					{
//						COXml				xml;
//
//						if (xml.init(&msgBS.DataMsg))
//						{
//							_StringManager.storeLog(xml);
//							success = true;
//						}
//						else
//						{
//							nlwarning("Failed to save string log file '%s' for database %d", msgBS.FileName.c_str(), _DatabaseId);
//						}
//					}
//
//					if (success)
//					{
//						PDBsi.sendFile(msgBS);
//					}
//				}
//				else
//				{
//					COFile				file;
//					{
//						COXml				xml;
//						if (file.open(logDir + logFile) && xml.init(&file))
//						{
//							_StringManager.storeLog(xml);
//						}
//						else
//						{
//							nlwarning("Failed to save string log file '%s' for database %d", (logDir+logFile).c_str(), _DatabaseId);
//						}
//					}
//				}
//			}

			_PreviousLogSave = ctime;

			// clean up for next update
			_DbMessageQueue.clear();
			_UpdateLogs.clear();

		}

		if (timestamp.toTime()-_LogStartDate.toTime() > sint(PDLogFileTime.get()))
		{
			_LogStartDate = timestamp;
		}

		_DbMessageQueue.forceNextQueue();
	}
}