/*
 * Drops a segment file.
 *
 */ 
static void
AppendOnlyCompaction_DropSegmentFile(Relation aorel,
		int segno)
{
	ItemPointerData persistentTid; 
	int64 persistentSerialNum;

	if (!ReadGpRelationNode(
					aorel->rd_node.relNode,
					segno,
					&persistentTid,
					&persistentSerialNum))
	{
		/* There is nothing to drop */
		return;
	}

	elogif(Debug_appendonly_print_compaction, LOG, 
		"Drop segment file: segno %d", segno);

	MirroredFileSysObj_ScheduleDropAppendOnlyFile(
			&aorel->rd_node,
			segno,
			RelationGetRelationName(aorel),
			&persistentTid,
			persistentSerialNum);

	DeleteGpRelationNodeTuple(aorel, segno);
}
Exemple #2
0
Fichier : aomd.c Projet : 50wu/gpdb
/*
 * Open an Append Only relation file segment
 *
 * The fd module's PathNameOpenFile() is used to open the file, so the
 * the File* routines can be used to read, write, close, etc, the file.
 */
bool
OpenAOSegmentFile(
					Relation rel, 
					char *filepathname, 
				  int32	segmentFileNum,
				  int64	logicalEof,
				  MirroredAppendOnlyOpen *mirroredOpen)
{	
	ItemPointerData persistentTid;
	int64 persistentSerialNum;

	int primaryError;

	if (!ReadGpRelationNode(
			rel->rd_rel->reltablespace,
			rel->rd_rel->relfilenode,
			segmentFileNum,
			&persistentTid,
			&persistentSerialNum))
	{
		if (logicalEof == 0)
			return false;

		elog(ERROR, "Did not find gp_relation_node entry for relation name %s, relation id %u, relfilenode %u, segment file #%d, logical eof " INT64_FORMAT,
			 rel->rd_rel->relname.data,
			 rel->rd_id,
			 rel->rd_node.relNode,
			 segmentFileNum,
			 logicalEof);
	}

	MirroredAppendOnly_OpenReadWrite(
							mirroredOpen, 
							&rel->rd_node,
							segmentFileNum,
							/* relationName */ NULL,		// Ok to be NULL -- we don't know the name here.
							logicalEof,
							/* traceOpenFlags */ false,
							&persistentTid,
							persistentSerialNum,
							&primaryError);
	if (primaryError != 0)
		ereport(ERROR,
			   (errcode_for_file_access(),
			    errmsg("Could not open Append-Only segment file '%s': %s",
					   filepathname,
					   strerror(primaryError))));

	return true;
}
/**
 * Drops a segment file.
 *
 */
static void
AOCSCompaction_DropSegmentFile(Relation aorel,
							   int segno)
{
	ItemPointerData persistentTid;
	int64		persistentSerialNum;
	int			pseudoSegNo;
	int			col;

	Assert(RelationIsAoCols(aorel));

	for (col = 0; col < RelationGetNumberOfAttributes(aorel); col++)
	{
		pseudoSegNo = (col * AOTupleId_MultiplierSegmentFileNum) + segno;

		if (!ReadGpRelationNode(
								aorel->rd_rel->reltablespace,
								aorel->rd_rel->relfilenode,
								pseudoSegNo,
								&persistentTid,
								&persistentSerialNum))
		{
			/* There is nothing to drop */
			return;
		}

		elogif(Debug_appendonly_print_compaction, LOG,
			   "Drop segment file: "
			   "segno %d",
			   pseudoSegNo);

		MirroredFileSysObj_ScheduleDropAppendOnlyFile(
													  &aorel->rd_node,
													  pseudoSegNo,
													  RelationGetRelationName(aorel),
													  &persistentTid,
													  persistentSerialNum);

		DeleteGpRelationNodeTuple(aorel,
								  pseudoSegNo);
	}
}
Exemple #4
0
void
datumstreamwrite_open_file(DatumStreamWrite * ds, char *fn, int64 eof, int64 eofUncompressed, RelFileNode relFileNode, int32 segmentFileNum, int version)
{
	ItemPointerData persistentTid;
	int64 persistentSerialNum;
	int64 appendOnlyNewEof;

	ds->eof = eof;
	ds->eofUncompress = eofUncompressed;

	if (ds->need_close_file)
		datumstreamwrite_close_file(ds);

	/*
	 * Segment file #0 is created when the Append-Only table is created.
	 *
	 * Other segment files are created on-demand under transaction.
	 */
	if (segmentFileNum > 0 && eof == 0)
	{
		AppendOnlyStorageWrite_TransactionCreateFile(
													 &ds->ao_write,
													 fn,
													 eof,
													 &relFileNode,
													 segmentFileNum,
													 &persistentTid,
													 &persistentSerialNum);
	}
	else
	{
		if (!ReadGpRelationNode(
				(relFileNode.spcNode == MyDatabaseTableSpace) ? 0:relFileNode.spcNode,
				relFileNode.relNode,
				segmentFileNum,
				&persistentTid,
				&persistentSerialNum))
		{
			elog(ERROR, "Did not find gp_relation_node entry for relfilenode %u, segment file #%d, logical eof " INT64_FORMAT,
				 relFileNode.relNode,
				 segmentFileNum,
				 eof);
		}
	}

	if (gp_appendonly_verify_eof)
	{
		appendOnlyNewEof = PersistentFileSysObj_ReadEof(
					PersistentFsObjType_RelationFile,
					&persistentTid);
		/*
		 * Verify if EOF from gp_persistent_relation_node < EOF from pg_aocsseg
		 *
		 * Note:- EOF from gp_persistent_relation_node has to be less than the
		 * EOF from pg_aocsseg because inside a transaction the actual EOF where
		 * the data is inserted has to be greater than or equal to Persistent
		 * Table (PT) stored EOF as persistent table EOF value is updated at the
		 * end of the transaction.
		 */
		if (eof < appendOnlyNewEof)
		{
			elog(ERROR, "Unexpected EOF for relfilenode %u,"
						" segment file %d: EOF from gp_persistent_relation_node "
						INT64_FORMAT " greater than current EOF " INT64_FORMAT,
						relFileNode.relNode,
						segmentFileNum,
						appendOnlyNewEof,
						eof);
		}
	}

	/*
	 * Open the existing file for write.
	 */
	AppendOnlyStorageWrite_OpenFile(&ds->ao_write,
									fn,
									version,
									eof,
									eofUncompressed,
									&relFileNode,
									segmentFileNum,
									&persistentTid,
									persistentSerialNum);

	ds->need_close_file = true;
}