Ejemplo n.º 1
0
/**
 * @brief Basic initialization.
 * @return true on success, false otherwise.
 */
bool CopyExecutor::DInit() {
  PELOTON_ASSERT(children_.size() == 1);

  // Grab info from plan node and check it
  const planner::CopyPlan &node = GetPlanNode<planner::CopyPlan>();

  bool success = InitFileHandle(node.file_path.c_str(), "w");

  if (success == false) {
    throw ExecutorException("Failed to create file " + node.file_path +
                            ". Try absolute path and make sure you have the "
                            "permission to access this file.");
    return false;
  }
  LOG_DEBUG("Created target copy output file: %s", node.file_path.c_str());

  // Whether we're copying the parameters which require deserialization
  if (node.deserialize_parameters) {
    InitParamColIds();
  }
  return true;
}
//-----------------------------------------------------------------------------------------------
// Close
//
// Closes the filehandle and takes care of flushing pages to the disk.
//-----------------------------------------------------------------------------------------------
t_rc STORM_FileHandle::Close()
{
	t_rc rc;

	// Check if file is not opened.
	if (!m_isOpened)
		return (STORM_FILEALREADYCLOSED);

	// Otherwise close the file and return OK.
	// Let the buffer manager deallocate space reserved for the file.
	rc = m_pBfrMgr->ReleaseFileFrames(m_fileID, true);
	if (rc != OK) return (rc);

	// Close the file (OS)
	int r;
	r = close(m_fileID);
	if (r) return (STORM_FILECLOSEERROR);

	// Initialize the file handle variables.
	InitFileHandle();
	
	return (OK);
}
//-----------------------------------------------------------------------------------------------
// Constructor
//
//
//-----------------------------------------------------------------------------------------------
STORM_FileHandle::STORM_FileHandle()
{
	InitFileHandle();
}