PostgreSQL Source Code: src/backend/utils/adt/lockfuncs.c File Reference (original) (raw)

Go to the source code of this file.

Macros
#define NUM_LOCK_STATUS_COLUMNS 16
#define SET_LOCKTAG_INT64(tag, key64)
#define SET_LOCKTAG_INT32(tag, key1, key2) SET_LOCKTAG_ADVISORY(tag, MyDatabaseId, key1, key2, 2)
Functions
StaticAssertDecl (lengthof(LockTagTypeNames)==(LOCKTAG_LAST_TYPE+1), "array length mismatch")
StaticAssertDecl (lengthof(PredicateLockTagTypeNames)==(PREDLOCKTAG_TUPLE+1), "array length mismatch")
static Datum VXIDGetDatum (ProcNumber procNumber, LocalTransactionId lxid)
Datum pg_lock_status (PG_FUNCTION_ARGS)
Datum pg_blocking_pids (PG_FUNCTION_ARGS)
Datum pg_safe_snapshot_blocking_pids (PG_FUNCTION_ARGS)
Datum pg_advisory_lock_int8 (PG_FUNCTION_ARGS)
Datum pg_advisory_xact_lock_int8 (PG_FUNCTION_ARGS)
Datum pg_advisory_lock_shared_int8 (PG_FUNCTION_ARGS)
Datum pg_advisory_xact_lock_shared_int8 (PG_FUNCTION_ARGS)
Datum pg_try_advisory_lock_int8 (PG_FUNCTION_ARGS)
Datum pg_try_advisory_xact_lock_int8 (PG_FUNCTION_ARGS)
Datum pg_try_advisory_lock_shared_int8 (PG_FUNCTION_ARGS)
Datum pg_try_advisory_xact_lock_shared_int8 (PG_FUNCTION_ARGS)
Datum pg_advisory_unlock_int8 (PG_FUNCTION_ARGS)
Datum pg_advisory_unlock_shared_int8 (PG_FUNCTION_ARGS)
Datum pg_advisory_lock_int4 (PG_FUNCTION_ARGS)
Datum pg_advisory_xact_lock_int4 (PG_FUNCTION_ARGS)
Datum pg_advisory_lock_shared_int4 (PG_FUNCTION_ARGS)
Datum pg_advisory_xact_lock_shared_int4 (PG_FUNCTION_ARGS)
Datum pg_try_advisory_lock_int4 (PG_FUNCTION_ARGS)
Datum pg_try_advisory_xact_lock_int4 (PG_FUNCTION_ARGS)
Datum pg_try_advisory_lock_shared_int4 (PG_FUNCTION_ARGS)
Datum pg_try_advisory_xact_lock_shared_int4 (PG_FUNCTION_ARGS)
Datum pg_advisory_unlock_int4 (PG_FUNCTION_ARGS)
Datum pg_advisory_unlock_shared_int4 (PG_FUNCTION_ARGS)
Datum pg_advisory_unlock_all (PG_FUNCTION_ARGS)

NUM_LOCK_STATUS_COLUMNS

#define NUM_LOCK_STATUS_COLUMNS 16

SET_LOCKTAG_INT32

SET_LOCKTAG_INT64

| #define SET_LOCKTAG_INT64 | ( | | tag, | | --------------------------- | - | | ---- | | | key64 | | | | | ) | | | |

Value:

(uint32) ((key64) >> 32), \

#define SET_LOCKTAG_ADVISORY(locktag, id1, id2, id3, id4)

Definition at line 613 of file lockfuncs.c.

pg_advisory_lock_int4()

pg_advisory_lock_int8()

pg_advisory_lock_shared_int4()

pg_advisory_lock_shared_int8()

pg_advisory_unlock_all()

pg_advisory_unlock_int4()

pg_advisory_unlock_int8()

pg_advisory_unlock_shared_int4()

pg_advisory_unlock_shared_int8()

pg_advisory_xact_lock_int4()

pg_advisory_xact_lock_int8()

pg_advisory_xact_lock_shared_int4()

pg_advisory_xact_lock_shared_int8()

pg_blocking_pids()

Definition at line 466 of file lockfuncs.c.

467{

469 Datum *arrayelems;

470 int narrayelems;

472 int i,

473 j;

474

475

477

478

480 narrayelems = 0;

481

482

483 for (i = 0; i < lockData->nprocs; i++)

484 {

490 int conflictMask;

491

492

493

494

495

496 blocked_instance = NULL;

498 {

500

501 if (instance->pid == bproc->pid)

502 {

503 Assert(blocked_instance == NULL);

504 blocked_instance = instance;

505 }

506 }

507 Assert(blocked_instance != NULL);

508

511

512

514 {

516

517

518 if (instance == blocked_instance)

519 continue;

520

522 continue;

523

524 if (conflictMask & instance->holdMask)

525 {

526

527 }

530 {

531

532 bool ahead = false;

533 int k;

534

536 {

537 if (preceding_waiters[k] == instance->pid)

538 {

539

540 ahead = true;

541 break;

542 }

543 }

544 if (!ahead)

545 continue;

546 }

547 else

548 {

549

550 continue;

551 }

552

553

555 }

556 }

557

558

559 Assert(narrayelems <= lockData->nlocks);

560

562}

#define PG_RETURN_ARRAYTYPE_P(x)

ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)

Assert(PointerIsAligned(start, uint64))

BlockedProcsData * GetBlockerStatusData(int blocked_pid)

LockMethod GetLockTagsMethodTable(const LOCKTAG *locktag)

#define LOCKBIT_ON(lockmode)

static Datum Int32GetDatum(int32 X)

const LOCKMASK * conflictTab

References Assert(), LockMethodData::conflictTab, construct_array_builtin(), BlockedProcData::first_lock, BlockedProcData::first_waiter, GetBlockerStatusData(), GetLockTagsMethodTable(), LockInstanceData::holdMask, i, Int32GetDatum(), j, LockInstanceData::leaderPid, LOCKBIT_ON, BlockedProcsData::locks, LockInstanceData::locktag, BlockedProcsData::nlocks, NoLock, BlockedProcsData::nprocs, BlockedProcData::num_locks, BlockedProcData::num_waiters, palloc(), PG_GETARG_INT32, PG_RETURN_ARRAYTYPE_P, LockInstanceData::pid, BlockedProcData::pid, BlockedProcsData::procs, BlockedProcsData::waiter_pids, and LockInstanceData::waitLockMode.

Referenced by pg_isolation_test_session_is_blocked().

pg_lock_status()

Definition at line 93 of file lockfuncs.c.

94{

99

101 {

104

105

107

108

109

110

112

113

114

117 TEXTOID, -1, 0);

119 OIDOID, -1, 0);

121 OIDOID, -1, 0);

123 INT4OID, -1, 0);

125 INT2OID, -1, 0);

127 TEXTOID, -1, 0);

129 XIDOID, -1, 0);

131 OIDOID, -1, 0);

133 OIDOID, -1, 0);

135 INT2OID, -1, 0);

137 TEXTOID, -1, 0);

139 INT4OID, -1, 0);

141 TEXTOID, -1, 0);

143 BOOLOID, -1, 0);

145 BOOLOID, -1, 0);

147 TIMESTAMPTZOID, -1, 0);

148

150

151

152

153

154

157

162

164 }

165

168 lockData = mystatus->lockData;

169

171 {

172 bool granted;

174 const char *locktypename;

175 char tnbuf[32];

181

182 instance = &(lockData->locks[mystatus->currIdx]);

183

184

185

186

187

188

189 granted = false;

191 {

193 {

195 {

196 granted = true;

198 break;

199 }

200 }

201 }

202

203

204

205

206

207 if (!granted)

208 {

210 {

211

213

214

215

216

217

219 }

220 else

221 {

222

223

224

225

227 continue;

228 }

229 }

230

231

232

233

234

237 else

238 {

239 snprintf(tnbuf, sizeof(tnbuf), "unknown %d",

241 locktypename = tnbuf;

242 }

244

246 {

251 nulls[3] = true;

252 nulls[4] = true;

253 nulls[5] = true;

254 nulls[6] = true;

255 nulls[7] = true;

256 nulls[8] = true;

257 nulls[9] = true;

258 break;

261 nulls[2] = true;

262 nulls[3] = true;

263 nulls[4] = true;

264 nulls[5] = true;

265 nulls[6] = true;

266 nulls[7] = true;

267 nulls[8] = true;

268 nulls[9] = true;

269 break;

274 nulls[4] = true;

275 nulls[5] = true;

276 nulls[6] = true;

277 nulls[7] = true;

278 nulls[8] = true;

279 nulls[9] = true;

280 break;

286 nulls[5] = true;

287 nulls[6] = true;

288 nulls[7] = true;

289 nulls[8] = true;

290 nulls[9] = true;

291 break;

295 nulls[1] = true;

296 nulls[2] = true;

297 nulls[3] = true;

298 nulls[4] = true;

299 nulls[5] = true;

300 nulls[7] = true;

301 nulls[8] = true;

302 nulls[9] = true;

303 break;

307 nulls[1] = true;

308 nulls[2] = true;

309 nulls[3] = true;

310 nulls[4] = true;

311 nulls[6] = true;

312 nulls[7] = true;

313 nulls[8] = true;

314 nulls[9] = true;

315 break;

320 nulls[1] = true;

321 nulls[2] = true;

322 nulls[3] = true;

323 nulls[4] = true;

324 nulls[5] = true;

325 nulls[7] = true;

326 nulls[9] = true;

327 break;

333 nulls[2] = true;

334 nulls[3] = true;

335 nulls[4] = true;

336 nulls[5] = true;

337 nulls[7] = true;

338 break;

342 default:

347 nulls[2] = true;

348 nulls[3] = true;

349 nulls[4] = true;

350 nulls[5] = true;

351 nulls[6] = true;

352 break;

353 }

354

356 if (instance->pid != 0)

358 else

359 nulls[11] = true;

363 if (!granted && instance->waitStart != 0)

365 else

366 nulls[15] = true;

367

371 }

372

373

374

375

376

379 {

381

388

390

391

392

393

394

395

397

399

400

405 else

406 nulls[4] = true;

410 else

411 nulls[3] = true;

412

413

414 nulls[5] = true;

415 nulls[6] = true;

416 nulls[7] = true;

417 nulls[8] = true;

418 nulls[9] = true;

419

420

423 if (xact->pid != 0)

425 else

426 nulls[11] = true;

427

428

429

430

431

435 nulls[15] = true;

436

440 }

441

443}

static Datum values[MAXATTR]

#define CStringGetTextDatum(s)

TupleDesc BlessTupleDesc(TupleDesc tupdesc)

#define SRF_IS_FIRSTCALL()

#define SRF_PERCALL_SETUP()

#define SRF_RETURN_NEXT(_funcctx, _result)

#define SRF_FIRSTCALL_INIT()

static Datum HeapTupleGetDatum(const HeapTupleData *tuple)

#define SRF_RETURN_DONE(_funcctx)

HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)

const char * GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode)

LockData * GetLockStatusData(void)

@ LOCKTAG_RELATION_EXTEND

@ LOCKTAG_SPECULATIVE_TOKEN

@ LOCKTAG_APPLY_TRANSACTION

@ LOCKTAG_DATABASE_FROZEN_IDS

@ LOCKTAG_VIRTUALTRANSACTION

#define LOCKBIT_OFF(lockmode)

#define LOCKTAG_LAST_TYPE

static Datum VXIDGetDatum(ProcNumber procNumber, LocalTransactionId lxid)

#define NUM_LOCK_STATUS_COLUMNS

static const char *const PredicateLockTagTypeNames[]

const char *const LockTagTypeNames[]

static MemoryContext MemoryContextSwitchTo(MemoryContext context)

static PgChecksumMode mode

static Datum TransactionIdGetDatum(TransactionId X)

static Datum Int16GetDatum(int16 X)

static Datum UInt16GetDatum(uint16 X)

static Datum BoolGetDatum(bool X)

static Datum ObjectIdGetDatum(Oid X)

static Datum UInt32GetDatum(uint32 X)

PredicateLockData * GetPredicateLockStatusData(void)

#define GET_PREDICATELOCKTARGETTAG_DB(locktag)

#define GET_PREDICATELOCKTARGETTAG_RELATION(locktag)

#define GET_PREDICATELOCKTARGETTAG_TYPE(locktag)

#define GET_PREDICATELOCKTARGETTAG_PAGE(locktag)

#define GET_PREDICATELOCKTARGETTAG_OFFSET(locktag)

MemoryContext multi_call_memory_ctx

uint8 locktag_lockmethodid

VirtualTransactionId vxid

PredicateLockData * predLockData

PREDICATELOCKTARGETTAG * locktags

VirtualTransactionId vxid

LocalTransactionId localTransactionId

TupleDesc CreateTemplateTupleDesc(int natts)

void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)

static Datum TimestampTzGetDatum(TimestampTz X)

References BlessTupleDesc(), BoolGetDatum(), CreateTemplateTupleDesc(), CStringGetTextDatum, PG_Lock_Status::currIdx, LockInstanceData::fastpath, GET_PREDICATELOCKTARGETTAG_DB, GET_PREDICATELOCKTARGETTAG_OFFSET, GET_PREDICATELOCKTARGETTAG_PAGE, GET_PREDICATELOCKTARGETTAG_RELATION, GET_PREDICATELOCKTARGETTAG_TYPE, GetLockmodeName(), GetLockStatusData(), GetPredicateLockStatusData(), heap_form_tuple(), HeapTupleGetDatum(), LockInstanceData::holdMask, Int16GetDatum(), Int32GetDatum(), VirtualTransactionId::localTransactionId, LOCKBIT_OFF, LOCKBIT_ON, PG_Lock_Status::lockData, LockData::locks, LockInstanceData::locktag, LOCKTAG_ADVISORY, LOCKTAG_APPLY_TRANSACTION, LOCKTAG_DATABASE_FROZEN_IDS, LOCKTAG::locktag_field1, LOCKTAG::locktag_field2, LOCKTAG::locktag_field3, LOCKTAG::locktag_field4, LOCKTAG_LAST_TYPE, LOCKTAG::locktag_lockmethodid, LOCKTAG_OBJECT, LOCKTAG_PAGE, LOCKTAG_RELATION, LOCKTAG_RELATION_EXTEND, LOCKTAG_SPECULATIVE_TOKEN, LOCKTAG_TRANSACTION, LOCKTAG_TUPLE, LOCKTAG::locktag_type, LOCKTAG_USERLOCK, LOCKTAG_VIRTUALTRANSACTION, PredicateLockData::locktags, LockTagTypeNames, MAX_LOCKMODES, MemoryContextSwitchTo(), mode, FuncCallContext::multi_call_memory_ctx, LockData::nelements, PredicateLockData::nelements, NoLock, NUM_LOCK_STATUS_COLUMNS, ObjectIdGetDatum(), palloc(), LockInstanceData::pid, SERIALIZABLEXACT::pid, PredicateLockTagTypeNames, PG_Lock_Status::predLockData, PG_Lock_Status::predLockIdx, PREDLOCKTAG_PAGE, PREDLOCKTAG_TUPLE, VirtualTransactionId::procNumber, snprintf, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, TimestampTzGetDatum(), TransactionIdGetDatum(), FuncCallContext::tuple_desc, TupleDescInitEntry(), UInt16GetDatum(), UInt32GetDatum(), FuncCallContext::user_fctx, values, LockInstanceData::vxid, SERIALIZABLEXACT::vxid, VXIDGetDatum(), LockInstanceData::waitLockMode, LockInstanceData::waitStart, while(), and PredicateLockData::xacts.

pg_safe_snapshot_blocking_pids()

pg_try_advisory_lock_int4()

pg_try_advisory_lock_int8()

pg_try_advisory_lock_shared_int4()

pg_try_advisory_lock_shared_int8()

pg_try_advisory_xact_lock_int4()

pg_try_advisory_xact_lock_int8()

pg_try_advisory_xact_lock_shared_int4()

pg_try_advisory_xact_lock_shared_int8()

StaticAssertDecl() [1/2]

StaticAssertDecl() [2/2]

VXIDGetDatum()

LockTagTypeNames

const char* const LockTagTypeNames[]

Initial value:

= {

"relation",

"extend",

"frozenid",

"page",

"tuple",

"transactionid",

"virtualxid",

"spectoken",

"object",

"userlock",

"advisory",

"applytransaction"

}

Definition at line 28 of file lockfuncs.c.

Referenced by GetLockNameFromTagType(), and pg_lock_status().

PredicateLockTagTypeNames

const char* const PredicateLockTagTypeNames[] static