* Create Storage User Mapping */
| 633 | * Create Storage User Mapping |
| 634 | */ |
| 635 | ObjectAddress |
| 636 | CreateStorageUserMapping(CreateStorageUserMappingStmt *stmt) |
| 637 | { |
| 638 | Relation rel; |
| 639 | Datum useoptions; |
| 640 | Datum values[Natts_gp_storage_user_mapping]; |
| 641 | bool nulls[Natts_gp_storage_user_mapping]; |
| 642 | HeapTuple tuple; |
| 643 | Oid useId; |
| 644 | Oid umId; |
| 645 | StorageServer *srv; |
| 646 | ObjectAddress myself; |
| 647 | RoleSpec *role = (RoleSpec *) stmt->user; |
| 648 | |
| 649 | rel = table_open(StorageUserMappingRelationId, RowExclusiveLock); |
| 650 | |
| 651 | if (role->roletype == ROLESPEC_PUBLIC) |
| 652 | useId = ACL_ID_PUBLIC; |
| 653 | else |
| 654 | useId = get_rolespec_oid(stmt->user, false); |
| 655 | |
| 656 | /* Check that the server exists. */ |
| 657 | srv = GetStorageServerByName(stmt->servername, false); |
| 658 | |
| 659 | storage_user_mapping_ddl_aclcheck(useId, srv->serverid, stmt->servername); |
| 660 | |
| 661 | /* |
| 662 | * Check that the user mapping is unique within server. |
| 663 | */ |
| 664 | umId = GetSysCacheOid2(STORAGEUSERMAPPINGUSERSERVER, Anum_gp_storage_user_mapping_oid, |
| 665 | ObjectIdGetDatum(useId), |
| 666 | ObjectIdGetDatum(srv->serverid)); |
| 667 | |
| 668 | if (OidIsValid(umId)) |
| 669 | { |
| 670 | if (stmt->if_not_exists) |
| 671 | { |
| 672 | ereport(NOTICE, |
| 673 | (errcode(ERRCODE_DUPLICATE_OBJECT), |
| 674 | errmsg("storage user mapping for \"%s\" already exists for storage server \"%s\", skipping", |
| 675 | StorageMappingUserName(useId), |
| 676 | stmt->servername))); |
| 677 | |
| 678 | table_close(rel, RowExclusiveLock); |
| 679 | return InvalidObjectAddress; |
| 680 | } |
| 681 | else |
| 682 | ereport(ERROR, |
| 683 | (errcode(ERRCODE_DUPLICATE_OBJECT), |
| 684 | errmsg("storage user mapping for \"%s\" already exists for storage server \"%s\"", |
| 685 | StorageMappingUserName(useId), |
| 686 | stmt->servername))); |
| 687 | } |
| 688 | |
| 689 | /* |
| 690 | * Insert tuple into gp_storage_user_mapping. |
| 691 | */ |
| 692 | memset(values, 0, sizeof(values)); |
no test coverage detected