* AssertPendingSyncs_RelationCache * * Assert that relcache.c and storage.c agree on whether to skip WAL. */
| 3226 | * Assert that relcache.c and storage.c agree on whether to skip WAL. |
| 3227 | */ |
| 3228 | void |
| 3229 | AssertPendingSyncs_RelationCache(void) |
| 3230 | { |
| 3231 | HASH_SEQ_STATUS status; |
| 3232 | LOCALLOCK *locallock; |
| 3233 | Relation *rels; |
| 3234 | int maxrels; |
| 3235 | int nrels; |
| 3236 | RelIdCacheEnt *idhentry; |
| 3237 | int i; |
| 3238 | |
| 3239 | /* |
| 3240 | * Open every relation that this transaction has locked. If, for some |
| 3241 | * relation, storage.c is skipping WAL and relcache.c is not skipping WAL, |
| 3242 | * a CommandCounterIncrement() typically yields a local invalidation |
| 3243 | * message that destroys the relcache entry. By recreating such entries |
| 3244 | * here, we detect the problem. |
| 3245 | */ |
| 3246 | PushActiveSnapshot(GetTransactionSnapshot()); |
| 3247 | maxrels = 1; |
| 3248 | rels = palloc(maxrels * sizeof(*rels)); |
| 3249 | nrels = 0; |
| 3250 | hash_seq_init(&status, GetLockMethodLocalHash()); |
| 3251 | while ((locallock = (LOCALLOCK *) hash_seq_search(&status)) != NULL) |
| 3252 | { |
| 3253 | Oid relid; |
| 3254 | Relation r; |
| 3255 | |
| 3256 | if (locallock->nLocks <= 0) |
| 3257 | continue; |
| 3258 | if ((LockTagType) locallock->tag.lock.locktag_type != |
| 3259 | LOCKTAG_RELATION) |
| 3260 | continue; |
| 3261 | relid = ObjectIdGetDatum(locallock->tag.lock.locktag_field2); |
| 3262 | r = RelationIdGetRelation(relid); |
| 3263 | if (!RelationIsValid(r)) |
| 3264 | continue; |
| 3265 | if (nrels >= maxrels) |
| 3266 | { |
| 3267 | maxrels *= 2; |
| 3268 | rels = repalloc(rels, maxrels * sizeof(*rels)); |
| 3269 | } |
| 3270 | rels[nrels++] = r; |
| 3271 | } |
| 3272 | |
| 3273 | hash_seq_init(&status, RelationIdCache); |
| 3274 | while ((idhentry = (RelIdCacheEnt *) hash_seq_search(&status)) != NULL) |
| 3275 | AssertPendingSyncConsistency(idhentry->reldesc); |
| 3276 | |
| 3277 | for (i = 0; i < nrels; i++) |
| 3278 | RelationClose(rels[i]); |
| 3279 | PopActiveSnapshot(); |
| 3280 | } |
| 3281 | #endif |
| 3282 | |
| 3283 | /* |
no test coverage detected