MCPcopy Create free account
hub / github.com/apache/cloudberry / SharedFileSetInit

Function SharedFileSetInit

src/backend/storage/file/sharedfileset.c:63–121  ·  view source on GitHub ↗

* Initialize a space for temporary files that can be opened by other backends. * Other backends must attach to it before accessing it. Associate this * SharedFileSet with 'seg'. Any contained files will be deleted when the * last backend detaches. * * We can also use this interface if the temporary files are used only by * single backend but the files need to be opened and closed multiple

Source from the content-addressed store, hash-verified

61 * be deleted.
62 */
63void
64SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg)
65{
66 static uint32 counter = 0;
67
68 SpinLockInit(&fileset->mutex);
69 fileset->refcnt = 1;
70 fileset->creator_pid = MyProcPid;
71 fileset->number = counter;
72 counter = (counter + 1) % INT_MAX;
73
74 /* Capture the tablespace OIDs so that all backends agree on them. */
75 PrepareTempTablespaces();
76 fileset->ntablespaces =
77 GetTempTablespaces(&fileset->tablespaces[0],
78 lengthof(fileset->tablespaces));
79 if (fileset->ntablespaces == 0)
80 {
81 /* If the GUC is empty, use current database's default tablespace */
82 fileset->tablespaces[0] = MyDatabaseTableSpace;
83 fileset->ntablespaces = 1;
84 }
85 else
86 {
87 int i;
88
89 /*
90 * An entry of InvalidOid means use the default tablespace for the
91 * current database. Replace that now, to be sure that all users of
92 * the SharedFileSet agree on what to do.
93 */
94 for (i = 0; i < fileset->ntablespaces; i++)
95 {
96 if (fileset->tablespaces[i] == InvalidOid)
97 fileset->tablespaces[i] = MyDatabaseTableSpace;
98 }
99 }
100
101 /* Register our cleanup callback. */
102 if (seg)
103 on_dsm_detach(seg, SharedFileSetOnDetach, PointerGetDatum(fileset));
104 else
105 {
106 static bool registered_cleanup = false;
107
108 if (!registered_cleanup)
109 {
110 /*
111 * We must not have registered any fileset before registering the
112 * fileset clean up.
113 */
114 Assert(filesetlist == NIL);
115 on_proc_exit(SharedFileSetDeleteOnProcExit, 0);
116 registered_cleanup = true;
117 }
118
119 filesetlist = lcons((void *) fileset, filesetlist);
120 }

Callers 5

subxact_info_writeFunction · 0.85
stream_open_fileFunction · 0.85
get_shareinput_filesetFunction · 0.85

Calls 5

PrepareTempTablespacesFunction · 0.85
GetTempTablespacesFunction · 0.85
on_dsm_detachFunction · 0.85
on_proc_exitFunction · 0.85
lconsFunction · 0.85

Tested by

no test coverage detected