* GetStorgeUserMapping - look up the storage user mapping. * * If no mapping is found for the supplied user, we also look for * PUBLIC mappings (userid == InvalidOid). */
| 136 | * PUBLIC mappings (userid == InvalidOid). |
| 137 | */ |
| 138 | StorageUserMapping * |
| 139 | GetStorageUserMapping(Oid userid, Oid serverid) |
| 140 | { |
| 141 | Datum datum; |
| 142 | HeapTuple tp; |
| 143 | bool isnull; |
| 144 | StorageUserMapping *um; |
| 145 | |
| 146 | tp = SearchSysCache2(STORAGEUSERMAPPINGUSERSERVER, |
| 147 | ObjectIdGetDatum(userid), |
| 148 | ObjectIdGetDatum(serverid)); |
| 149 | |
| 150 | if (!HeapTupleIsValid(tp)) |
| 151 | { |
| 152 | /* Not found for the specific user -- try PUBLIC */ |
| 153 | tp = SearchSysCache2(STORAGEUSERMAPPINGUSERSERVER, |
| 154 | ObjectIdGetDatum(InvalidOid), |
| 155 | ObjectIdGetDatum(serverid)); |
| 156 | } |
| 157 | |
| 158 | if (!HeapTupleIsValid(tp)) |
| 159 | ereport(ERROR, |
| 160 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 161 | errmsg("storage user mapping not found for \"%s\"", |
| 162 | StorageMappingUserName(userid)))); |
| 163 | |
| 164 | um = (StorageUserMapping *) palloc(sizeof(StorageUserMapping)); |
| 165 | um->umid = ((Form_gp_storage_user_mapping) GETSTRUCT(tp))->oid; |
| 166 | um->userid = userid; |
| 167 | um->serverid = serverid; |
| 168 | |
| 169 | /* Extract the umoptions */ |
| 170 | datum = SysCacheGetAttr(STORAGEUSERMAPPINGUSERSERVER, |
| 171 | tp, |
| 172 | Anum_gp_storage_user_mapping_umoptions, |
| 173 | &isnull); |
| 174 | if (isnull) |
| 175 | um->options = NIL; |
| 176 | else |
| 177 | um->options = untransformRelOptions(datum); |
| 178 | |
| 179 | ReleaseSysCache(tp); |
| 180 | |
| 181 | return um; |
| 182 | } |
| 183 | |
| 184 | |
| 185 | /* |
nothing calls this directly
no test coverage detected