Esempio n. 1
0
/*
 * Create a BufFile for a new temporary file (which will expand to become
 * multiple temporary files if more than MAX_PHYSICAL_FILESIZE bytes are
 * written to it).
 *
 * If interXact is true, the temp file will not be automatically deleted
 * at end of transaction.
 *
 * Note: if interXact is true, the caller had better be calling us in a
 * memory context that will survive across transaction boundaries.
 */
BufFile *
BufFileCreateTemp(bool interXact)
{
	BufFile    *file;
	File		pfile;

	pfile = OpenTemporaryFile(interXact);
	Assert(pfile >= 0);

	file = makeBufFile(pfile);
	file->isTemp = true;
	file->isInterXact = interXact;

	/*
	 * add by cywang
	 *
	 * to record the time of read data from disk
	 */
	file->instr_fileload = InstrAlloc(1,1);
	file->fileLoadNum = 0;
	file->instr_filedump = InstrAlloc(1,1);
	file->fileDumpNum = 0;

	return file;
}
Esempio n. 2
0
/*
 * Opens an existing file as BufFile
 *
 * If create is true, the file is created if it doesn't exist.
 *
 * Does not add the pgsql_tmp/ prefix to the file path before opening.
 *
 */
BufFile *
BufFileOpenFile(const char *fileName, bool create, bool delOnClose, bool interXact)
{
	bool closeAtEOXact = !interXact;
	File pfile = OpenNamedFile(fileName,
							  create,
							  delOnClose,
							  closeAtEOXact); /* closeAtEOXact */
	/*
	 * If we are trying to open an existing file and it failed,
	 * signal this to the caller.
	 */
	if (!create && pfile <= 0)
	{
		return NULL;
	}

	Assert(pfile >= 0);

	BufFile *file = makeBufFile(pfile);
	file->isTemp = delOnClose;
	if (!create)
	{
		/* Open existing file, initialize its size */
		file->maxoffset = FileDiskSize(file->file);
	}

	return file;

}
Esempio n. 3
0
/*
 * Create a BufFile for a new temporary file (which will expand to become
 * multiple temporary files if more than MAX_PHYSICAL_FILESIZE bytes are
 * written to it).
 *
 * If interXact is true, the temp file will not be automatically deleted
 * at end of transaction.
 *
 * Note: if interXact is true, the caller had better be calling us in a
 * memory context, and with a resource owner, that will survive across
 * transaction boundaries.
 */
BufFile *
BufFileCreateTemp(bool interXact)
{
	BufFile    *file;
	File		pfile;

	pfile = OpenTemporaryFile(interXact);
	Assert(pfile >= 0);

	file = makeBufFile(pfile);
	file->isInterXact = interXact;

	return file;
}
Esempio n. 4
0
/*
 * Create a BufFile for a new temporary file.
 *
 * Adds the pgsql_tmp/ prefix to the file path before creating.
 *
 * Note: if interXact is true, the caller had better be calling us in a
 * memory context that will survive across transaction boundaries.
 */
BufFile *
BufFileCreateTemp(const char *filePrefix, bool interXact)
{
	BufFile	   *file;
	File		pfile;
	bool		closeAtEOXact = !interXact;

	pfile = OpenTemporaryFile(filePrefix,
							  true, /* makenameunique */
							  true, /* create */
							  true, /* delOnClose */
							  closeAtEOXact); /* closeAtEOXact */
	Assert(pfile >= 0);

	file = makeBufFile(pfile);
	file->isTemp = true;

	return file;
}
Esempio n. 5
0
/*
 * Create a BufFile for a new temporary file used for writer-reader exchange.
 *
 * Adds the pgsql_tmp/ prefix to the file path before creating.
 *
 */
BufFile *
BufFileCreateTemp_ReaderWriter(const char *filePrefix, bool isWriter,
							   bool interXact)
{
	bool closeAtEOXact = !interXact;
	File pfile = OpenTemporaryFile(filePrefix,
								   false, /* makenameunique */
								   isWriter, /* create */
								   isWriter, /* delOnClose */
								   closeAtEOXact); /* closeAtEOXact */
	if (pfile < 0)
	{
		elog(ERROR, "could not open temporary file \"%s\": %m", filePrefix);
	}

	BufFile *file = makeBufFile(pfile);
	file->isTemp = true;

	return file;
}
Esempio n. 6
0
/*
 * Create a BufFile and attach it to an already-opened virtual File.
 *
 * This is comparable to fdopen() in stdio.  This is the only way at present
 * to attach a BufFile to a non-temporary file.  Note that BufFiles created
 * in this way CANNOT be expanded into multiple files.
 */
BufFile *
BufFileCreate(File file)
{
	return makeBufFile(file);
}