Header And Logo

| The world's most advanced open source database.

Data Structures | Defines | Typedefs | Functions

storage_xlog.h File Reference

#include "access/xlog.h"
#include "storage/block.h"
#include "storage/relfilenode.h"
Include dependency graph for storage_xlog.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  xl_smgr_create
struct  xl_smgr_truncate


#define XLOG_SMGR_CREATE   0x10
#define XLOG_SMGR_TRUNCATE   0x20


typedef struct xl_smgr_create xl_smgr_create
typedef struct xl_smgr_truncate xl_smgr_truncate


void log_smgrcreate (RelFileNode *rnode, ForkNumber forkNum)
void smgr_redo (XLogRecPtr lsn, XLogRecord *record)
void smgr_desc (StringInfo buf, uint8 xl_info, char *rec)

Define Documentation

#define XLOG_SMGR_CREATE   0x10

Definition at line 29 of file storage_xlog.h.

Referenced by log_smgrcreate(), smgr_desc(), and smgr_redo().

#define XLOG_SMGR_TRUNCATE   0x20

Definition at line 30 of file storage_xlog.h.

Referenced by RelationTruncate(), smgr_desc(), and smgr_redo().

Typedef Documentation

Function Documentation

void log_smgrcreate ( RelFileNode rnode,
ForkNumber  forkNum 

Definition at line 123 of file storage.c.

References XLogRecData::buffer, XLogRecData::data, xl_smgr_create::forkNum, XLogRecData::len, XLogRecData::next, xl_smgr_create::rnode, XLOG_SMGR_CREATE, and XLogInsert().

Referenced by heap_create_init_fork(), and RelationCreateStorage().

    xl_smgr_create xlrec;
    XLogRecData rdata;

     * Make an XLOG entry reporting the file creation.
    xlrec.rnode = *rnode;
    xlrec.forkNum = forkNum;

    rdata.data = (char *) &xlrec;
    rdata.len = sizeof(xlrec);
    rdata.buffer = InvalidBuffer;
    rdata.next = NULL;

    XLogInsert(RM_SMGR_ID, XLOG_SMGR_CREATE, &rdata);

void smgr_desc ( StringInfo  buf,
uint8  xl_info,
char *  rec 

Definition at line 23 of file smgrdesc.c.

References appendStringInfo(), xl_smgr_truncate::blkno, xl_smgr_create::forkNum, MAIN_FORKNUM, pfree(), relpathperm, xl_smgr_truncate::rnode, xl_smgr_create::rnode, XLOG_SMGR_CREATE, and XLOG_SMGR_TRUNCATE.

    uint8       info = xl_info & ~XLR_INFO_MASK;

    if (info == XLOG_SMGR_CREATE)
        xl_smgr_create *xlrec = (xl_smgr_create *) rec;
        char       *path = relpathperm(xlrec->rnode, xlrec->forkNum);

        appendStringInfo(buf, "file create: %s", path);
    else if (info == XLOG_SMGR_TRUNCATE)
        xl_smgr_truncate *xlrec = (xl_smgr_truncate *) rec;
        char       *path = relpathperm(xlrec->rnode, MAIN_FORKNUM);

        appendStringInfo(buf, "file truncate: %s to %u blocks", path,
        appendStringInfo(buf, "UNKNOWN");

void smgr_redo ( XLogRecPtr  lsn,
XLogRecord record 

Definition at line 476 of file storage.c.

References Assert, xl_smgr_truncate::blkno, CreateFakeRelcacheEntry(), elog, xl_smgr_create::forkNum, FreeFakeRelcacheEntry(), FreeSpaceMapTruncateRel(), FSM_FORKNUM, InvalidBackendId, MAIN_FORKNUM, PANIC, xl_smgr_truncate::rnode, xl_smgr_create::rnode, smgrcreate(), smgrexists(), smgropen(), smgrtruncate(), VISIBILITYMAP_FORKNUM, visibilitymap_truncate(), XLogRecord::xl_info, XLOG_SMGR_CREATE, XLOG_SMGR_TRUNCATE, XLogFlush(), XLogRecGetData, XLogTruncateRelation(), and XLR_BKP_BLOCK_MASK.

    uint8       info = record->xl_info & ~XLR_INFO_MASK;

    /* Backup blocks are not used in smgr records */
    Assert(!(record->xl_info & XLR_BKP_BLOCK_MASK));

    if (info == XLOG_SMGR_CREATE)
        xl_smgr_create *xlrec = (xl_smgr_create *) XLogRecGetData(record);
        SMgrRelation reln;

        reln = smgropen(xlrec->rnode, InvalidBackendId);
        smgrcreate(reln, xlrec->forkNum, true);
    else if (info == XLOG_SMGR_TRUNCATE)
        xl_smgr_truncate *xlrec = (xl_smgr_truncate *) XLogRecGetData(record);
        SMgrRelation reln;
        Relation    rel;

        reln = smgropen(xlrec->rnode, InvalidBackendId);

         * Forcibly create relation if it doesn't exist (which suggests that
         * it was dropped somewhere later in the WAL sequence).  As in
         * XLogReadBuffer, we prefer to recreate the rel and replay the log as
         * best we can until the drop is seen.
        smgrcreate(reln, MAIN_FORKNUM, true);

         * Before we perform the truncation, update minimum recovery point
         * to cover this WAL record. Once the relation is truncated, there's
         * no going back. The buffer manager enforces the WAL-first rule
         * for normal updates to relation files, so that the minimum recovery
         * point is always updated before the corresponding change in the
         * data file is flushed to disk. We have to do the same manually
         * here.
         * Doing this before the truncation means that if the truncation fails
         * for some reason, you cannot start up the system even after restart,
         * until you fix the underlying situation so that the truncation will
         * succeed. Alternatively, we could update the minimum recovery point
         * after truncation, but that would leave a small window where the
         * WAL-first rule could be violated.

        smgrtruncate(reln, MAIN_FORKNUM, xlrec->blkno);

        /* Also tell xlogutils.c about it */
        XLogTruncateRelation(xlrec->rnode, MAIN_FORKNUM, xlrec->blkno);

        /* Truncate FSM and VM too */
        rel = CreateFakeRelcacheEntry(xlrec->rnode);

        if (smgrexists(reln, FSM_FORKNUM))
            FreeSpaceMapTruncateRel(rel, xlrec->blkno);
        if (smgrexists(reln, VISIBILITYMAP_FORKNUM))
            visibilitymap_truncate(rel, xlrec->blkno);

        elog(PANIC, "smgr_redo: unknown op code %u", info);