示例#1
0
void
PersistentRelation_RemoveSegment(int16 dbid, bool ismirror)
{
    Relation rel;
    HeapScanDesc scandesc;
    HeapTuple tuple;
    WRITE_PERSISTENT_STATE_ORDERED_LOCK_DECLARE;

    if (Persistent_BeforePersistenceWork())
        elog(ERROR, "persistent table changes forbidden");

    rel = heap_open(GpPersistentRelationNodeRelationId,
                    AccessExclusiveLock);
    scandesc = heap_beginscan(rel, SnapshotNow, 0, NULL);

    WRITE_PERSISTENT_STATE_ORDERED_LOCK;

    while ((tuple = heap_getnext(scandesc, ForwardScanDirection)) != NULL)
    {
        Form_gp_persistent_relation_node form =
            (Form_gp_persistent_relation_node)GETSTRUCT(tuple);
        Oid tblspcoid = form->tablespace_oid;
        Oid dboid = form->database_oid;
        Oid relfilenode_oid = form->relfilenode_oid;
        int32 segment_file_num = form->segment_file_num;
        int64 serial = form->persistent_serial_num;

        PersistentFileSysObjName fsObjName;
        RelFileNode node;

        node.spcNode = tblspcoid;
        node.dbNode = dboid;
        node.relNode = relfilenode_oid;

        PersistentFileSysObjName_SetRelationFile(&fsObjName,
                &node,
                segment_file_num);

        PersistentFileSysObj_RemoveSegment(&fsObjName,
                                           &tuple->t_self,
                                           serial,
                                           dbid,
                                           ismirror,
                                           /* flushToXlog */ false);
    }

    WRITE_PERSISTENT_STATE_ORDERED_UNLOCK;
    heap_endscan(scandesc);
    heap_close(rel, NoLock);
}
void
PersistentTablespace_RemoveSegment(int16 dbid, bool ismirror)
{
	TablespaceDirEntry tablespaceDirEntry;
	HASH_SEQ_STATUS hstat;

	WRITE_PERSISTENT_STATE_ORDERED_LOCK_DECLARE;

	hash_seq_init(&hstat, persistentTablespaceSharedHashTable);

	if (Persistent_BeforePersistenceWork())
		elog(ERROR, "persistent table changes forbidden");

	PersistentTablespace_VerifyInitScan();

	WRITE_PERSISTENT_STATE_ORDERED_LOCK;

	LWLockAcquire(TablespaceHashLock, LW_SHARED);
	while ((tablespaceDirEntry = hash_seq_search(&hstat)) != NULL)
	{
		PersistentFileSysObjName fsObjName;
		Oid			tblspc = tablespaceDirEntry->key.tablespaceOid;
		ItemPointerData persistentTid;
		uint64		persistentSerialNum;

		tablespaceDirEntry = PersistentTablespace_FindEntryUnderLock(tblspc);

		LWLockRelease(TablespaceHashLock);

		if (tablespaceDirEntry == NULL)
			elog(ERROR, "Did not find persistent tablespace entry %u",
				 tblspc);
		persistentSerialNum = tablespaceDirEntry->persistentSerialNum;
		ItemPointerCopy(&tablespaceDirEntry->persistentTid, &persistentTid);

		PersistentFileSysObjName_SetTablespaceDir(&fsObjName, tblspc);

		PersistentFileSysObj_RemoveSegment(&fsObjName,
										   &persistentTid,
										   persistentSerialNum,
										   dbid,
										   ismirror,
										    /* flushToXlog */ false);
		LWLockAcquire(TablespaceHashLock, LW_SHARED);
	}
	LWLockRelease(TablespaceHashLock);

	WRITE_PERSISTENT_STATE_ORDERED_UNLOCK;
}
示例#3
0
/*
 * Remove all reference to a segment from the gp_persistent_filespace_node table
 * and share memory structure.
 */
void
PersistentFilespace_RemoveSegment(int16 dbid, bool ismirror)
{
	HASH_SEQ_STATUS hstat;
	FilespaceDirEntry fde;
	WRITE_PERSISTENT_STATE_ORDERED_LOCK_DECLARE;

	if (Persistent_BeforePersistenceWork())
		elog(ERROR, "persistent table changes forbidden");

	hash_seq_init(&hstat, persistentFilespaceSharedHashTable);

	PersistentFilespace_VerifyInitScan();

	WRITE_PERSISTENT_STATE_ORDERED_LOCK;

	while ((fde = hash_seq_search(&hstat)) != NULL)
	{
		Oid filespace = fde->key.filespaceOid;
		PersistentFileSysObjName fsObjName;

		PersistentFileSysObjName_SetFilespaceDir(&fsObjName, filespace);

		if (fde->dbId1 == dbid)
		{
			PersistentFilespace_BlankPadCopyLocation(
										fde->locationBlankPadded1,
										"");
		}
		else if (fde->dbId2 == dbid)
		{
			PersistentFilespace_BlankPadCopyLocation(
										fde->locationBlankPadded2,
										"");
		}

		PersistentFileSysObj_RemoveSegment(&fsObjName,
								   &fde->persistentTid,
								   fde->persistentSerialNum,
								   dbid,
								   ismirror,
								   /* flushToXlog */ false);
	}
	WRITE_PERSISTENT_STATE_ORDERED_UNLOCK;
}
/*
 * Remove all reference to a segment from the gp_persistent_filespace_node table
 * and share memory structure.
 */
void
PersistentFilespace_RemoveSegment(int16 dbid, bool ismirror)
{
	HASH_SEQ_STATUS hstat;
	FilespaceDirEntry fde;
	WRITE_PERSISTENT_STATE_ORDERED_LOCK_DECLARE;

	if (Persistent_BeforePersistenceWork())
		elog(ERROR, "persistent table changes forbidden");

	hash_seq_init(&hstat, persistentFilespaceSharedHashTable);

	PersistentFilespace_VerifyInitScan();

	WRITE_PERSISTENT_STATE_ORDERED_LOCK;

	/*
	 * We release FilespaceHashLock in the middle of the loop and re-acquire
	 * it after doing persistent table change.  This is needed to prevent
	 * holding the lock for any purpose other than to protect the filespace
	 * shared hash table.  Not releasing this lock could result in file I/O
	 * and potential deadlock due to other LW locks being acquired in the
	 * process.  Releasing the lock this way is safe because we are still
	 * holding PersistentObjLock in exclusive mode.  Any change to the
	 * filespace shared hash table is also protected by PersistentObjLock.
	 */
	WRITE_FILESPACE_HASH_LOCK;
	while ((fde = hash_seq_search(&hstat)) != NULL)
	{
		Oid filespace = fde->key.filespaceOid;
		PersistentFileSysObjName fsObjName;
		ItemPointerData persistentTid;
		int64 persistentSerialNum = fde->persistentSerialNum;

		ItemPointerCopy(&fde->persistentTid, &persistentTid);

		PersistentFileSysObjName_SetFilespaceDir(&fsObjName, filespace);

		if (fde->dbId1 == dbid)
		{
			PersistentFilespace_BlankPadCopyLocation(
										fde->locationBlankPadded1,
										"");
		}
		else if (fde->dbId2 == dbid)
		{
			PersistentFilespace_BlankPadCopyLocation(
										fde->locationBlankPadded2,
										"");
		}

		WRITE_FILESPACE_HASH_UNLOCK;

		PersistentFileSysObj_RemoveSegment(&fsObjName,
								   &persistentTid,
								   persistentSerialNum,
								   dbid,
								   ismirror,
								   /* flushToXlog */ false);
		WRITE_FILESPACE_HASH_LOCK;
	}
	WRITE_FILESPACE_HASH_UNLOCK;
	
	WRITE_PERSISTENT_STATE_ORDERED_UNLOCK;
}