Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Functions | Variables

buf_table.c File Reference

#include "postgres.h"
#include "storage/bufmgr.h"
#include "storage/buf_internals.h"
Include dependency graph for buf_table.c:

Go to the source code of this file.

Data Structures

struct  BufferLookupEnt

Functions

Size BufTableShmemSize (int size)
void InitBufTable (int size)
uint32 BufTableHashCode (BufferTag *tagPtr)
int BufTableLookup (BufferTag *tagPtr, uint32 hashcode)
int BufTableInsert (BufferTag *tagPtr, uint32 hashcode, int buf_id)
void BufTableDelete (BufferTag *tagPtr, uint32 hashcode)

Variables

static HTABSharedBufHash

Function Documentation

void BufTableDelete ( BufferTag tagPtr,
uint32  hashcode 
)

Definition at line 151 of file buf_table.c.

References elog, ERROR, hash_search_with_hash_value(), and among::result.

Referenced by BufferAlloc(), and InvalidateBuffer().

{
    BufferLookupEnt *result;

    result = (BufferLookupEnt *)
        hash_search_with_hash_value(SharedBufHash,
                                    (void *) tagPtr,
                                    hashcode,
                                    HASH_REMOVE,
                                    NULL);

    if (!result)                /* shouldn't happen */
        elog(ERROR, "shared buffer hash table corrupted");
}

uint32 BufTableHashCode ( BufferTag tagPtr  ) 

Definition at line 81 of file buf_table.c.

References get_hash_value().

Referenced by BufferAlloc(), InvalidateBuffer(), and PrefetchBuffer().

{
    return get_hash_value(SharedBufHash, (void *) tagPtr);
}

int BufTableInsert ( BufferTag tagPtr,
uint32  hashcode,
int  buf_id 
)

Definition at line 121 of file buf_table.c.

References Assert, buftag::blockNum, hash_search_with_hash_value(), BufferLookupEnt::id, P_NEW, and among::result.

Referenced by BufferAlloc().

{
    BufferLookupEnt *result;
    bool        found;

    Assert(buf_id >= 0);        /* -1 is reserved for not-in-table */
    Assert(tagPtr->blockNum != P_NEW);  /* invalid tag */

    result = (BufferLookupEnt *)
        hash_search_with_hash_value(SharedBufHash,
                                    (void *) tagPtr,
                                    hashcode,
                                    HASH_ENTER,
                                    &found);

    if (found)                  /* found something already in the table */
        return result->id;

    result->id = buf_id;

    return -1;
}

int BufTableLookup ( BufferTag tagPtr,
uint32  hashcode 
)

Definition at line 93 of file buf_table.c.

References hash_search_with_hash_value(), BufferLookupEnt::id, and among::result.

Referenced by BufferAlloc(), and PrefetchBuffer().

{
    BufferLookupEnt *result;

    result = (BufferLookupEnt *)
        hash_search_with_hash_value(SharedBufHash,
                                    (void *) tagPtr,
                                    hashcode,
                                    HASH_FIND,
                                    NULL);

    if (!result)
        return -1;

    return result->id;
}

Size BufTableShmemSize ( int  size  ) 

Definition at line 43 of file buf_table.c.

References hash_estimate_size().

Referenced by StrategyShmemSize().

{
    return hash_estimate_size(size, sizeof(BufferLookupEnt));
}

void InitBufTable ( int  size  ) 

Definition at line 53 of file buf_table.c.

References HASHCTL::entrysize, HASHCTL::hash, HASH_ELEM, HASH_FUNCTION, HASH_PARTITION, HASHCTL::keysize, HASHCTL::num_partitions, and ShmemInitHash().

Referenced by StrategyInitialize().

{
    HASHCTL     info;

    /* assume no locking is needed yet */

    /* BufferTag maps to Buffer */
    info.keysize = sizeof(BufferTag);
    info.entrysize = sizeof(BufferLookupEnt);
    info.hash = tag_hash;
    info.num_partitions = NUM_BUFFER_PARTITIONS;

    SharedBufHash = ShmemInitHash("Shared Buffer Lookup Table",
                                  size, size,
                                  &info,
                                  HASH_ELEM | HASH_FUNCTION | HASH_PARTITION);
}


Variable Documentation

HTAB* SharedBufHash [static]

Definition at line 35 of file buf_table.c.