PostgreSQL Source Code  git master
sharedfileset.c File Reference
#include "postgres.h"
#include <limits.h>
#include "storage/dsm.h"
#include "storage/sharedfileset.h"
Include dependency graph for sharedfileset.c:

Go to the source code of this file.

Functions

static void SharedFileSetOnDetach (dsm_segment *segment, Datum datum)
 
void SharedFileSetInit (SharedFileSet *fileset, dsm_segment *seg)
 
void SharedFileSetAttach (SharedFileSet *fileset, dsm_segment *seg)
 
void SharedFileSetDeleteAll (SharedFileSet *fileset)
 

Function Documentation

◆ SharedFileSetAttach()

void SharedFileSetAttach ( SharedFileSet fileset,
dsm_segment seg 
)

Definition at line 56 of file sharedfileset.c.

57 {
58  bool success;
59 
60  SpinLockAcquire(&fileset->mutex);
61  if (fileset->refcnt == 0)
62  success = false;
63  else
64  {
65  ++fileset->refcnt;
66  success = true;
67  }
68  SpinLockRelease(&fileset->mutex);
69 
70  if (!success)
71  ereport(ERROR,
72  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
73  errmsg("could not attach to a SharedFileSet that is already destroyed")));
74 
75  /* Register our cleanup callback. */
77 }
void on_dsm_detach(dsm_segment *seg, on_dsm_detach_callback function, Datum arg)
Definition: dsm.c:1132
int errcode(int sqlerrcode)
Definition: elog.c:855
int errmsg(const char *fmt,...)
Definition: elog.c:1068
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
static bool success
Definition: initdb.c:186
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
static void SharedFileSetOnDetach(dsm_segment *segment, Datum datum)
Definition: sharedfileset.c:96
#define SpinLockRelease(lock)
Definition: spin.h:64
#define SpinLockAcquire(lock)
Definition: spin.h:62

References ereport, errcode(), errmsg(), ERROR, SharedFileSet::mutex, on_dsm_detach(), PointerGetDatum(), SharedFileSet::refcnt, SharedFileSetOnDetach(), SpinLockAcquire, SpinLockRelease, and success.

Referenced by ExecHashJoinInitializeWorker(), and tuplesort_attach_shared().

◆ SharedFileSetDeleteAll()

void SharedFileSetDeleteAll ( SharedFileSet fileset)

Definition at line 83 of file sharedfileset.c.

84 {
85  FileSetDeleteAll(&fileset->fs);
86 }
void FileSetDeleteAll(FileSet *fileset)
Definition: fileset.c:150

References FileSetDeleteAll(), and SharedFileSet::fs.

Referenced by ExecHashJoinReInitializeDSM().

◆ SharedFileSetInit()

void SharedFileSetInit ( SharedFileSet fileset,
dsm_segment seg 
)

Definition at line 38 of file sharedfileset.c.

39 {
40  /* Initialize the shared fileset specific members. */
41  SpinLockInit(&fileset->mutex);
42  fileset->refcnt = 1;
43 
44  /* Initialize the fileset. */
45  FileSetInit(&fileset->fs);
46 
47  /* Register our cleanup callback. */
48  if (seg)
50 }
void FileSetInit(FileSet *fileset)
Definition: fileset.c:52
#define SpinLockInit(lock)
Definition: spin.h:60

References FileSetInit(), SharedFileSet::fs, SharedFileSet::mutex, on_dsm_detach(), PointerGetDatum(), SharedFileSet::refcnt, SharedFileSetOnDetach(), and SpinLockInit.

Referenced by ExecHashJoinInitializeDSM(), and tuplesort_initialize_shared().

◆ SharedFileSetOnDetach()

static void SharedFileSetOnDetach ( dsm_segment segment,
Datum  datum 
)
static

Definition at line 96 of file sharedfileset.c.

97 {
98  bool unlink_all = false;
99  SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum);
100 
101  SpinLockAcquire(&fileset->mutex);
102  Assert(fileset->refcnt > 0);
103  if (--fileset->refcnt == 0)
104  unlink_all = true;
105  SpinLockRelease(&fileset->mutex);
106 
107  /*
108  * If we are the last to detach, we delete the directory in all
109  * tablespaces. Note that we are still actually attached for the rest of
110  * this function so we can safely access its data.
111  */
112  if (unlink_all)
113  FileSetDeleteAll(&fileset->fs);
114 }
#define Assert(condition)
Definition: c.h:858
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312

References Assert, DatumGetPointer(), FileSetDeleteAll(), SharedFileSet::fs, SharedFileSet::mutex, SharedFileSet::refcnt, SpinLockAcquire, and SpinLockRelease.

Referenced by SharedFileSetAttach(), and SharedFileSetInit().