sqldata/sqldata.cpp
// Get next metadata/schema task for processing
Get next metadata/schema task for processing
Get next metadata / schema task for processing
bool SqlData::GetNextMetaTask(SqlMetaTask &task)
{
	SqlMetaTask first_task;
	bool exists = false;
	bool first = true;
	Os::EnterCriticalSection(&_task_queue_critical_section);
	while(_meta_tasks.empty() == false)
	{
		task = _meta_tasks.front();
		_meta_tasks.pop_front();
		bool data_complete = IsDataTransferred(task.s_name);
		bool pk_created = true;
		if(task.type == SQLDATA_CMD_ADD_FOREIGN_KEY && data_complete == true)
			pk_created = IsPrimaryKeyCreated(task);
		if(task.type == SQLDATA_CMD_CREATE_TRIGGER && data_complete == true && pk_created == true)
			pk_created = IsSequencesCreated();
		bool ddl_exists = IsDdlRunning(task.s_name);
		if(data_complete == false || pk_created == false || ddl_exists)
		{
			if(first == true)
			{
				_meta_tasks.push_back(task);
				first_task.type = task.type;
				first_task.s_name = task.s_name;
				first_task.statement = task.statement;
				first = false;
			}
			else
			{
				if(first_task.type == task.type && first_task.s_name == task.s_name &&
					first_task.statement == task.statement)
				{
					Os::LeaveCriticalSection(&_task_queue_critical_section);
					Os::Sleep(1);
					Os::EnterCriticalSection(&_task_queue_critical_section);
				}
				_meta_tasks.push_back(task);
			}
			continue;
		}
		exists = true;
		break;
	}
	_meta_in_progress.push_back(task);
	Os::LeaveCriticalSection(&_task_queue_critical_section);
	return exists;
}
bool SqlData :: GetNextMetaTask ( SqlMetaTask & task ) { SqlMetaTask first_task ; bool exists = false ; bool first = true ; Os :: EnterCriticalSection ( & _task_queue_critical_section ) ; while ( _meta_tasks . empty ( ) == false ) { task = _meta_tasks . front ( ) ; _meta_tasks . pop_front ( ) ; bool data_complete = IsDataTransferred ( task . s_name ) ; bool pk_created = true ; if ( task . type == SQLDATA_CMD_ADD_FOREIGN_KEY && data_complete == true ) pk_created = IsPrimaryKeyCreated ( task ) ; if ( task . type == SQLDATA_CMD_CREATE_TRIGGER && data_complete == true && pk_created == true ) pk_created = IsSequencesCreated ( ) ; bool ddl_exists = IsDdlRunning ( task . s_name ) ; if ( data_complete == false || pk_created == false || ddl_exists ) { if ( first == true ) { _meta_tasks . push_back ( task ) ; first_task . type = task . type ; first_task . s_name = task . s_name ; first_task . statement = task . statement ; first = false ; } else { if ( first_task . type == task . type && first_task . s_name == task . s_name && first_task . statement == task . statement ) { Os :: LeaveCriticalSection ( & _task_queue_critical_section ) ; Os :: Sleep ( 1 ) ; Os :: EnterCriticalSection ( & _task_queue_critical_section ) ; } _meta_tasks . push_back ( task ) ; } continue ; } exists = true ; break ; } _meta_in_progress . push_back ( task ) ; Os :: LeaveCriticalSection ( & _task_queue_critical_section ) ; return exists ; }
Get next metadata/schema task for processing
Get next metadata / schema task for processing
// Get the next task from the queue // Check whether data of the table already transferred // For foreign key task check if the primary key was already created // For trigger task, check that all sequences already created // Due to locks, do not perform DDL operations on the same object in parallel // We cannot execute this task now // Save the first task to prevent loops // Return task back to the list // Save pointers // Make sure we did not select the first task again (loop) // Temporary leave the critical section to allow other threads to do work  // Return task back to the list