Use SnapshotDirty for reading metadata in truncation

merge-cstore-pykello
Hadi Moshayedi 2020-10-05 14:18:29 -07:00
parent 55885c81dd
commit 76a71aa61a
3 changed files with 5 additions and 11 deletions

View File

@ -20,6 +20,7 @@
#include "storage/bufpage.h" #include "storage/bufpage.h"
#include "storage/lockdefs.h" #include "storage/lockdefs.h"
#include "utils/relcache.h" #include "utils/relcache.h"
#include "utils/snapmgr.h"
/* Defines for valid option names */ /* Defines for valid option names */
#define OPTION_NAME_COMPRESSION_TYPE "compression" #define OPTION_NAME_COMPRESSION_TYPE "compression"

View File

@ -377,7 +377,8 @@ ReadDataFileMetadata(Oid relfilenode, bool missingOk)
index = index_open(CStoreStripesIndexRelationId(), AccessShareLock); index = index_open(CStoreStripesIndexRelationId(), AccessShareLock);
tupleDescriptor = RelationGetDescr(cstoreStripes); tupleDescriptor = RelationGetDescr(cstoreStripes);
scanDescriptor = systable_beginscan_ordered(cstoreStripes, index, NULL, 1, scanKey); scanDescriptor = systable_beginscan_ordered(cstoreStripes, index, NULL, 1,
scanKey);
while (HeapTupleIsValid(heapTuple = systable_getnext(scanDescriptor))) while (HeapTupleIsValid(heapTuple = systable_getnext(scanDescriptor)))
{ {

View File

@ -631,7 +631,7 @@ LogRelationStats(Relation rel, int elevel)
TupleDesc tupdesc = RelationGetDescr(rel); TupleDesc tupdesc = RelationGetDescr(rel);
uint64 droppedBlocksWithData = 0; uint64 droppedBlocksWithData = 0;
datafileMetadata = ReadDataFileMetadata(relfilenode); datafileMetadata = ReadDataFileMetadata(relfilenode, false);
stripeCount = list_length(datafileMetadata->stripeMetadataList); stripeCount = list_length(datafileMetadata->stripeMetadataList);
foreach(stripeMetadataCell, datafileMetadata->stripeMetadataList) foreach(stripeMetadataCell, datafileMetadata->stripeMetadataList)
@ -765,15 +765,7 @@ TruncateCStore(Relation rel, int elevel)
old_rel_pages = smgrnblocks(rel->rd_smgr, MAIN_FORKNUM); old_rel_pages = smgrnblocks(rel->rd_smgr, MAIN_FORKNUM);
RelationCloseSmgr(rel); RelationCloseSmgr(rel);
/* metadata = ReadDataFileMetadata(rel->rd_node.relNode, false);
* Get metadata as viewed in latest snapshot. Reading metadata in transaction
* snapshot is not enough, since stripes could have been created between
* current transaction start and lock acquisition time. Ignoring those
* stripes can destory data.
*/
PushActiveSnapshot(GetLatestSnapshot());
metadata = ReadDataFileMetadata(rel->rd_node.relNode);
PopActiveSnapshot();
/* loop over stripes and find max used block */ /* loop over stripes and find max used block */
foreach(stripeMetadataCell, metadata->stripeMetadataList) foreach(stripeMetadataCell, metadata->stripeMetadataList)