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

Function sts_initialize

src/backend/utils/sort/sharedtuplestore.c:126–171  ·  view source on GitHub ↗

* Initialize a SharedTuplestore in existing shared memory. There must be * space for sts_estimate(participants) bytes. If flags includes the value * SHARED_TUPLESTORE_SINGLE_PASS, the files may in future be removed more * eagerly (but this isn't yet implemented). * * Tuples that are stored may optionally carry a piece of fixed sized * meta-data which will be retrieved along with the tuple.

Source from the content-addressed store, hash-verified

124 * across all SharedTuplestores created in the same SharedFileSet.
125 */
126SharedTuplestoreAccessor *
127sts_initialize(SharedTuplestore *sts, int participants,
128 int my_participant_number,
129 size_t meta_data_size,
130 int flags,
131 SharedFileSet *fileset,
132 const char *name)
133{
134 SharedTuplestoreAccessor *accessor;
135 int i;
136
137 Assert(my_participant_number < participants);
138
139 sts->nparticipants = participants;
140 sts->meta_data_size = meta_data_size;
141 sts->flags = flags;
142
143 if (strlen(name) > sizeof(sts->name) - 1)
144 elog(ERROR, "SharedTuplestore name too long");
145 strcpy(sts->name, name);
146
147 /*
148 * Limit meta-data so it + tuple size always fits into a single chunk.
149 * sts_puttuple() and sts_read_tuple() could be made to support scenarios
150 * where that's not the case, but it's not currently required. If so,
151 * meta-data size probably should be made variable, too.
152 */
153 if (meta_data_size + sizeof(uint32) >= STS_CHUNK_DATA_SIZE)
154 elog(ERROR, "meta-data too long");
155
156 for (i = 0; i < participants; ++i)
157 {
158 LWLockInitialize(&sts->participants[i].lock,
159 LWTRANCHE_SHARED_TUPLESTORE);
160 sts->participants[i].read_page = 0;
161 sts->participants[i].writing = false;
162 }
163
164 accessor = palloc0(sizeof(SharedTuplestoreAccessor));
165 accessor->participant = my_participant_number;
166 accessor->sts = sts;
167 accessor->fileset = fileset;
168 accessor->context = CurrentMemoryContext;
169
170 return accessor;
171}
172
173/*
174 * Attach to a SharedTuplestore that has been initialized by another backend,

Callers 1

Calls 2

LWLockInitializeFunction · 0.85
palloc0Function · 0.50

Tested by

no test coverage detected