mirror of https://github.com/citusdata/citus.git
Refactor UpdateStripeMetadataRow for improved readability and consistency
parent
e9e976d331
commit
fc93466516
|
@ -1392,14 +1392,16 @@ UpdateStripeMetadataRow(uint64 storageId, uint64 stripeId, bool *update,
|
||||||
Oid columnarStripesOid = ColumnarStripeRelationId();
|
Oid columnarStripesOid = ColumnarStripeRelationId();
|
||||||
|
|
||||||
#if PG_VERSION_NUM >= 180000
|
#if PG_VERSION_NUM >= 180000
|
||||||
/* CatalogTupleUpdate performs a normal heap UPDATE → RowExclusiveLock */
|
|
||||||
const LOCKMODE openLockMode = RowExclusiveLock;
|
/* CatalogTupleUpdate performs a normal heap UPDATE → RowExclusiveLock */
|
||||||
|
const LOCKMODE openLockMode = RowExclusiveLock;
|
||||||
#else
|
#else
|
||||||
/* In‑place update never changed tuple length → AccessShareLock was enough */
|
|
||||||
const LOCKMODE openLockMode = AccessShareLock;
|
/* In‑place update never changed tuple length → AccessShareLock was enough */
|
||||||
|
const LOCKMODE openLockMode = AccessShareLock;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Relation columnarStripes = table_open(columnarStripesOid, openLockMode);
|
Relation columnarStripes = table_open(columnarStripesOid, openLockMode);
|
||||||
|
|
||||||
Oid indexId = ColumnarStripePKeyIndexRelationId();
|
Oid indexId = ColumnarStripePKeyIndexRelationId();
|
||||||
bool indexOk = OidIsValid(indexId);
|
bool indexOk = OidIsValid(indexId);
|
||||||
|
@ -1413,43 +1415,47 @@ UpdateStripeMetadataRow(uint64 storageId, uint64 stripeId, bool *update,
|
||||||
loggedSlowMetadataAccessWarning = true;
|
loggedSlowMetadataAccessWarning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
HeapTuple oldTuple = systable_getnext(scanDescriptor);
|
HeapTuple oldTuple = systable_getnext(scanDescriptor);
|
||||||
if (!HeapTupleIsValid(oldTuple))
|
if (!HeapTupleIsValid(oldTuple))
|
||||||
ereport(ERROR,
|
{
|
||||||
(errmsg("attempted to modify an unexpected stripe, "
|
ereport(ERROR,
|
||||||
"columnar storage with id=" UINT64_FORMAT
|
(errmsg("attempted to modify an unexpected stripe, "
|
||||||
" does not have stripe with id=" UINT64_FORMAT,
|
"columnar storage with id=" UINT64_FORMAT
|
||||||
storageId, stripeId)));
|
" does not have stripe with id=" UINT64_FORMAT,
|
||||||
|
storageId, stripeId)));
|
||||||
|
}
|
||||||
|
|
||||||
/* ---------------- construct the new tuple ---------------- */
|
/* ---------------- construct the new tuple ---------------- */
|
||||||
bool newNulls[Natts_columnar_stripe] = {false};
|
bool newNulls[Natts_columnar_stripe] = { false };
|
||||||
TupleDesc tupleDescriptor = RelationGetDescr(columnarStripes);
|
TupleDesc tupleDescriptor = RelationGetDescr(columnarStripes);
|
||||||
HeapTuple modifiedTuple = heap_modify_tuple(oldTuple,
|
HeapTuple modifiedTuple = heap_modify_tuple(oldTuple,
|
||||||
tupleDescriptor,
|
tupleDescriptor,
|
||||||
newValues,
|
newValues,
|
||||||
newNulls,
|
newNulls,
|
||||||
update);
|
update);
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 180000
|
#if PG_VERSION_NUM < 180000
|
||||||
/* Fast path: true in‑place update (same physical tuple) */
|
|
||||||
heap_inplace_update(columnarStripes, modifiedTuple);
|
/* Fast path: true in‑place update (same physical tuple) */
|
||||||
HeapTuple newTuple = oldTuple; /* contents overwritten in place */
|
heap_inplace_update(columnarStripes, modifiedTuple);
|
||||||
|
HeapTuple newTuple = oldTuple; /* contents overwritten in place */
|
||||||
#else
|
#else
|
||||||
/* Regular catalog UPDATE keeps indexes in sync */
|
|
||||||
CatalogTupleUpdate(columnarStripes, &oldTuple->t_self, modifiedTuple);
|
/* Regular catalog UPDATE keeps indexes in sync */
|
||||||
HeapTuple newTuple = modifiedTuple; /* freshly written tuple */
|
CatalogTupleUpdate(columnarStripes, &oldTuple->t_self, modifiedTuple);
|
||||||
|
HeapTuple newTuple = modifiedTuple; /* freshly written tuple */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CommandCounterIncrement();
|
CommandCounterIncrement();
|
||||||
|
|
||||||
/* Build StripeMetadata from the up‑to‑date tuple */
|
/* Build StripeMetadata from the up‑to‑date tuple */
|
||||||
StripeMetadata *modifiedStripeMetadata =
|
StripeMetadata *modifiedStripeMetadata =
|
||||||
BuildStripeMetadata(columnarStripes, newTuple);
|
BuildStripeMetadata(columnarStripes, newTuple);
|
||||||
|
|
||||||
systable_endscan(scanDescriptor);
|
systable_endscan(scanDescriptor);
|
||||||
table_close(columnarStripes, openLockMode);
|
table_close(columnarStripes, openLockMode);
|
||||||
|
|
||||||
return modifiedStripeMetadata;
|
return modifiedStripeMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue