示例#1
0
static void GetFilespacePathForTablespace(
	Oid tablespaceOid,

	char **filespacePath)
{
	PersistentTablespaceGetFilespaces tablespaceGetFilespaces;
	Oid filespaceOid;

	/* All other tablespaces are accessed via filespace locations */
	char *primary_path;
	char *mirror_path;	/* unused */

	Assert(tablespaceOid != GLOBALTABLESPACE_OID);
	Assert(tablespaceOid != DEFAULTTABLESPACE_OID);
	
	/* Lookup filespace location from the persistent object layer. */
	tablespaceGetFilespaces = 
			PersistentTablespace_TryGetPrimaryAndMirrorFilespaces(
														tablespaceOid, 
														&primary_path, 
														&mirror_path,
														&filespaceOid);
	switch (tablespaceGetFilespaces)
	{
	case PersistentTablespaceGetFilespaces_TablespaceNotFound:
		ereport(ERROR, 
				(errcode(ERRCODE_CDB_INTERNAL_ERROR),
				 errmsg("Unable to find entry for tablespace OID = %u when forming file-system path",
						tablespaceOid)));
		break;
			
	case PersistentTablespaceGetFilespaces_FilespaceNotFound:
		ereport(ERROR, 
				(errcode(ERRCODE_CDB_INTERNAL_ERROR),
				 errmsg("Unable to find entry for filespace OID = %u when forming file-system path for tablespace OID = %u",
				 		filespaceOid,
						tablespaceOid)));
		break;
					
	case PersistentTablespaceGetFilespaces_Ok:
		// Go below and pass back the result.
		break;
		
	default:
		elog(ERROR, "Unexpected tablespace filespace fetch result: %d",
			 tablespaceGetFilespaces);
	}
	
	/*
	 * We immediately throw out the mirror_path because it is not
	 * relevant here.
	 */
	if (mirror_path)
		pfree(mirror_path);
	Assert(primary_path != NULL);

	*filespacePath = primary_path;
}
void
PersistentTablespace_GetPrimaryAndMirrorFilespaces(
												   Oid tablespaceOid,
 /* The tablespace OID for the create. */

												   char **primaryFilespaceLocation,
 /* The primary filespace directory path.  Return NULL for global and base. */

												   char **mirrorFilespaceLocation)

 /*
  * The primary filespace directory path.  Return NULL for global and base.
  * Or, returns NULL when mirror not configured.
  */
{
	PersistentTablespaceGetFilespaces tablespaceGetFilespaces;

	Oid			filespaceOid;

	/*
	 * Do not call PersistentTablepace_VerifyInitScan here to allow
	 * PersistentTablespace_TryGetPrimaryAndMirrorFilespaces to handle the
	 * Standby Master special case.
	 */

	tablespaceGetFilespaces =
		PersistentTablespace_TryGetPrimaryAndMirrorFilespaces(
															  tablespaceOid,
															  primaryFilespaceLocation,
															  mirrorFilespaceLocation,
															  &filespaceOid);
	switch (tablespaceGetFilespaces)
	{
		case PersistentTablespaceGetFilespaces_TablespaceNotFound:
			ereport(ERROR,
					(errcode(ERRCODE_INTERNAL_ERROR),
					 errmsg("Unable to find entry for tablespace OID = %u when getting filespace directory paths",
							tablespaceOid)));
			break;

		case PersistentTablespaceGetFilespaces_FilespaceNotFound:
			ereport(ERROR,
					(errcode(ERRCODE_INTERNAL_ERROR),
					 errmsg("Unable to find entry for filespace OID = %u when forming filespace directory paths for tablespace OID = %u",
							filespaceOid,
							tablespaceOid)));
			break;

		case PersistentTablespaceGetFilespaces_Ok:
			/* Go below and pass back the result. */
			break;

		default:
			elog(ERROR, "Unexpected tablespace filespace fetch result: %d",
				 tablespaceGetFilespaces);
	}
}