184 #define IsSpecInsert(action) \
186 ((action) == REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT) \
188 #define IsSpecConfirmOrAbort(action) \
190 (((action) == REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM) || \
191 ((action) == REORDER_BUFFER_CHANGE_INTERNAL_SPEC_ABORT)) \
193 #define IsInsertOrUpdate(action) \
195 (((action) == REORDER_BUFFER_CHANGE_INSERT) || \
196 ((action) == REORDER_BUFFER_CHANGE_UPDATE) || \
197 ((action) == REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT)) \
302 bool addition,
Size sz);
325 memset(&hash_ctl, 0,
sizeof(hash_ctl));
454 if (txn->
gid != NULL)
515 if (change->
data.
tp.newtuple)
518 change->
data.
tp.newtuple = NULL;
521 if (change->
data.
tp.oldtuple)
524 change->
data.
tp.oldtuple = NULL;
528 if (change->
data.
msg.prefix != NULL)
530 change->
data.
msg.prefix = NULL;
531 if (change->
data.
msg.message != NULL)
533 change->
data.
msg.message = NULL;
608 alloc_len =
sizeof(
Oid) * nrelids;
632 bool *is_new,
XLogRecPtr lsn,
bool create_as_top)
706 Assert(!create || txn != NULL);
753 change->
data.
tp.clear_toast_afterwards)
853 bool transactional,
const char *prefix,
854 Size message_size,
const char *message)
875 change->
data.
msg.message_size = message_size;
877 memcpy(change->
data.
msg.message, message, message_size);
886 volatile Snapshot snapshot_now = snap;
898 rb->
message(rb, txn, lsn,
false, prefix, message_size, message);
922 #ifdef USE_ASSERT_CHECKING
955 Assert(prev_first_lsn < cur_txn->first_lsn);
975 Assert(prev_base_snap_lsn < cur_txn->base_snapshot_lsn);
993 #ifdef USE_ASSERT_CHECKING
1010 Assert(prev_lsn <= cur_change->lsn);
1012 prev_lsn = cur_change->
lsn;
1247 else if (pos_a == pos_b)
1302 state->nr_txns = nr_txns;
1305 for (off = 0; off <
state->nr_txns; off++)
1307 state->entries[off].file.vfd = -1;
1308 state->entries[off].segno = 0;
1317 *iter_state =
state;
1336 &
state->entries[off].segno);
1342 state->entries[off].lsn = cur_change->
lsn;
1343 state->entries[off].change = cur_change;
1344 state->entries[off].txn = txn;
1365 &
state->entries[off].file,
1366 &
state->entries[off].segno);
1371 state->entries[off].lsn = cur_change->
lsn;
1372 state->entries[off].change = cur_change;
1373 state->entries[off].txn = cur_txn;
1397 if (
state->heap->bh_size == 0)
1401 entry = &
state->entries[off];
1427 state->entries[off].lsn = next_change->
lsn;
1428 state->entries[off].change = next_change;
1451 &
state->entries[off].segno))
1458 elog(
DEBUG2,
"restored %u/%u changes from disk",
1464 state->entries[off].lsn = next_change->
lsn;
1465 state->entries[off].change = next_change;
1487 for (off = 0; off <
state->nr_txns; off++)
1489 if (
state->entries[off].file.vfd != -1)
2009 int nrelations,
Relation *relations,
2028 change->
data.
msg.message_size,
2033 change->
data.
msg.message_size,
2048 if (snapshot_now->
copied)
2076 if (specinsert != NULL)
2120 volatile bool stream_started =
false;
2144 int changes_count = 0;
2182 stream_started =
true;
2193 prev_lsn = change->
lsn;
2202 curtxn = change->
txn;
2215 if (specinsert == NULL)
2216 elog(
ERROR,
"invalid ordering of speculative insertion changes");
2218 change = specinsert;
2228 change->
data.
tp.rlocator.relNumber);
2243 change->
data.
tp.newtuple == NULL &&
2244 change->
data.
tp.oldtuple == NULL)
2247 elog(
ERROR,
"could not map filenumber \"%s\" to relation OID",
2254 elog(
ERROR,
"could not open relation with OID %u (for filenumber \"%s\")",
2275 if (relation->
rd_rel->relkind == RELKIND_SEQUENCE)
2290 if (change->
data.
tp.clear_toast_afterwards)
2317 if (specinsert != NULL)
2346 if (specinsert != NULL)
2354 specinsert = change;
2367 if (specinsert != NULL)
2391 for (
i = 0;
i < nrelids;
i++)
2399 elog(
ERROR,
"could not open relation with OID %u", relid);
2404 relations[nrelations++] = rel;
2412 for (
i = 0;
i < nrelations;
i++)
2432 if (snapshot_now->
copied)
2463 if (command_id < change->
data.command_id)
2467 if (!snapshot_now->
copied)
2474 snapshot_now->
curcid = command_id;
2483 elog(
ERROR,
"tuplecid value in changequeue");
2497 #define CHANGES_THRESHOLD 100
2536 stream_started =
false;
2546 rb->
prepare(rb, txn, commit_lsn);
2548 rb->
commit(rb, txn, commit_lsn);
2553 elog(
ERROR,
"output plugin used XID %u",
2562 else if (snapshot_now->
copied)
2641 if (errdata->
sqlerrcode == ERRCODE_TRANSACTION_ROLLBACK &&
2655 command_id, prev_lsn,
2755 origin_id, origin_lsn);
2850 XLogRecPtr origin_lsn,
char *gid,
bool is_commit)
2866 prepare_end_lsn = txn->
end_lsn;
2880 if ((txn->
final_lsn < two_phase_at) && is_commit)
3113 for (
i = 0;
i < ninvalidations;
i++)
3224 bool addition,
Size sz)
3372 change->
data.
inval.ninvalidations = nmsgs;
3375 memcpy(change->
data.
inval.invalidations, msgs,
3392 for (
i = 0;
i < nmsgs;
i++)
3459 xids[xcnt++] = txn->
xid;
3596 Size largest_size = 0;
3611 if ((largest == NULL || txn->
total_size > largest_size) &&
3719 elog(
DEBUG2,
"spill %u changes in XID %u to disk",
3761 O_CREAT | O_WRONLY | O_APPEND |
PG_BINARY);
3766 errmsg(
"could not open file \"%s\": %m", path)));
3830 oldtup = change->
data.
tp.oldtuple;
3831 newtup = change->
data.
tp.newtuple;
3836 oldlen = oldtup->
t_len;
3843 newlen = newtup->
t_len;
3876 Size prefix_size = strlen(change->
data.
msg.prefix) + 1;
3878 sz += prefix_size + change->
data.
msg.message_size +
3888 memcpy(
data, &prefix_size,
sizeof(
Size));
3892 data += prefix_size;
3898 change->
data.
msg.message_size);
3991 int save_errno = errno;
3996 errno = save_errno ? save_errno : ENOSPC;
3999 errmsg(
"could not write to data file for XID %u: %m",
4060 bool txn_is_streamed;
4189 oldtup = change->
data.
tp.oldtuple;
4190 newtup = change->
data.
tp.newtuple;
4195 oldlen = oldtup->
t_len;
4202 newlen = newtup->
t_len;
4210 Size prefix_size = strlen(change->
data.
msg.prefix) + 1;
4212 sz += prefix_size + change->
data.
msg.message_size +
4311 if (*
fd < 0 && errno == ENOENT)
4320 errmsg(
"could not open file \"%s\": %m",
4332 file->
curOffset, WAIT_EVENT_REORDER_BUFFER_READ);
4342 else if (readBytes < 0)
4345 errmsg(
"could not read from reorderbuffer spill file: %m")));
4349 errmsg(
"could not read from reorderbuffer spill file: read %d instead of %u bytes",
4365 WAIT_EVENT_REORDER_BUFFER_READ);
4370 errmsg(
"could not read from reorderbuffer spill file: %m")));
4374 errmsg(
"could not read from reorderbuffer spill file: read %d instead of %u bytes",
4423 if (change->
data.
tp.oldtuple)
4427 change->
data.
tp.oldtuple =
4436 change->
data.
tp.oldtuple->t_data =
4440 memcpy(change->
data.
tp.oldtuple->t_data,
data, tuplelen);
4444 if (change->
data.
tp.newtuple)
4452 change->
data.
tp.newtuple =
4461 change->
data.
tp.newtuple->t_data =
4465 memcpy(change->
data.
tp.newtuple->t_data,
data, tuplelen);
4475 memcpy(&prefix_size,
data,
sizeof(
Size));
4479 memcpy(change->
data.
msg.prefix,
data, prefix_size);
4481 data += prefix_size;
4487 change->
data.
msg.message_size);
4489 change->
data.
msg.message_size);
4586 if (unlink(path) != 0 && errno != ENOENT)
4589 errmsg(
"could not remove file \"%s\": %m", path)));
4602 struct stat statbuf;
4615 if (strncmp(spill_de->
d_name,
"xid", 3) == 0)
4621 if (unlink(path) != 0)
4624 errmsg(
"could not remove file \"%s\" during removal of %s/%s/xid*: %m",
4658 struct dirent *logical_de;
4663 if (strcmp(logical_de->
d_name,
".") == 0 ||
4664 strcmp(logical_de->
d_name,
"..") == 0)
4727 newtup = change->
data.
tp.newtuple;
4746 elog(
ERROR,
"got sequence entry %d for toast chunk %u instead of seq 0",
4747 chunk_seq, chunk_id);
4750 elog(
ERROR,
"got sequence entry %d for toast chunk %u instead of seq %d",
4763 elog(
ERROR,
"unexpected type of toast chunk");
4765 ent->
size += chunksize;
4832 elog(
ERROR,
"could not open toast relation with OID %u (base relation \"%s\")",
4842 newtup = change->
data.
tp.newtuple;
4846 for (natt = 0; natt < desc->
natts; natt++)
4855 struct varlena *new_datum = NULL;
4856 struct varlena *reconstructed;
4861 if (attr->attnum < 0)
4864 if (attr->attisdropped)
4868 if (attr->attlen != -1)
4913 ctup = cchange->
data.
tp.newtuple;
4920 memcpy(
VARDATA(reconstructed) + data_done,
4933 memset(&redirect_pointer, 0,
sizeof(redirect_pointer));
4934 redirect_pointer.
pointer = reconstructed;
4938 sizeof(redirect_pointer));
4961 for (natt = 0; natt < desc->
natts; natt++)
5062 elog(
DEBUG3,
"mapping: node: %u/%u/%u tid: %u/%u cmin: %u, cmax: %u",
5094 errmsg(
"could not open file \"%s\": %m", path)));
5114 errmsg(
"could not read file \"%s\": %m",
5116 else if (readBytes == 0)
5121 errmsg(
"could not read from file \"%s\": read %d instead of %d bytes",
5166 errmsg(
"could not close file \"%s\": %m", path)));
5176 return bsearch(&xid, xip, num,
5200 struct dirent *mapping_de;
5217 if (strcmp(mapping_de->
d_name,
".") == 0 ||
5218 strcmp(mapping_de->
d_name,
"..") == 0)
5222 if (strncmp(mapping_de->
d_name,
"map-", 4) != 0)
5226 &f_dboid, &f_relid, &f_hi, &f_lo,
5227 &f_mapped_xid, &f_create_xid) != 6)
5230 f_lsn = ((
uint64) f_hi) << 32 | f_lo;
5233 if (f_dboid != dboid)
5237 if (f_relid != relid)
5259 foreach(file, files)
5284 bool updated_mapping =
false;
5298 memset(&
key, 0,
sizeof(
key));
5325 if (ent == NULL && !updated_mapping)
5329 updated_mapping =
true;
5332 else if (ent == NULL)
void binaryheap_build(binaryheap *heap)
void binaryheap_replace_first(binaryheap *heap, bh_node_type d)
bh_node_type binaryheap_first(binaryheap *heap)
bh_node_type binaryheap_remove_first(binaryheap *heap)
binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
void binaryheap_free(binaryheap *heap)
void binaryheap_add_unordered(binaryheap *heap, bh_node_type d)
static void cleanup(void)
#define BufferIsLocal(buffer)
void BufferGetTag(Buffer buffer, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum)
#define Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
bool IsToastRelation(Relation relation)
bool IsSharedRelation(Oid relationId)
#define INDIRECT_POINTER_SIZE
#define VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr)
void hash_destroy(HTAB *hashp)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
void * hash_seq_search(HASH_SEQ_STATUS *status)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
void FreeErrorData(ErrorData *edata)
int errcode_for_file_access(void)
void FlushErrorState(void)
int errmsg(const char *fmt,...)
ErrorData * CopyErrorData(void)
#define ereport(elevel,...)
struct dirent * ReadDir(DIR *dir, const char *dirname)
int CloseTransientFile(int fd)
void FileClose(File file)
File PathNameOpenFile(const char *fileName, int fileFlags)
struct dirent * ReadDirExtended(DIR *dir, const char *dirname, int elevel)
int OpenTransientFile(const char *fileName, int fileFlags)
DIR * AllocateDir(const char *dirname)
static ssize_t FileRead(File file, void *buffer, size_t amount, off_t offset, uint32 wait_event_info)
MemoryContext GenerationContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
HeapTupleData * HeapTuple
struct HeapTupleData HeapTupleData
HeapTupleHeaderData * HeapTupleHeader
#define SizeofHeapTupleHeader
static Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
#define dlist_foreach(iter, lhead)
static void dlist_init(dlist_head *head)
#define dclist_container(type, membername, ptr)
static bool dlist_has_next(const dlist_head *head, const dlist_node *node)
static void dclist_push_tail(dclist_head *head, dlist_node *node)
static void dlist_insert_before(dlist_node *before, dlist_node *node)
#define dlist_head_element(type, membername, lhead)
static void dlist_delete(dlist_node *node)
static uint32 dclist_count(const dclist_head *head)
static dlist_node * dlist_next_node(dlist_head *head, dlist_node *node)
static dlist_node * dlist_pop_head_node(dlist_head *head)
#define dlist_foreach_modify(iter, lhead)
static bool dlist_is_empty(const dlist_head *head)
static void dlist_push_tail(dlist_head *head, dlist_node *node)
static void dclist_delete_from(dclist_head *head, dlist_node *node)
static void dclist_init(dclist_head *head)
#define dlist_container(type, membername, ptr)
#define dclist_foreach(iter, lhead)
static int pg_cmp_u64(uint64 a, uint64 b)
void LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg)
if(TABLE==NULL||TABLE_index==NULL)
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
static void ItemPointerCopy(const ItemPointerData *fromPointer, ItemPointerData *toPointer)
void list_sort(List *list, list_sort_comparator cmp)
List * lappend(List *list, void *datum)
void UpdateDecodingStats(LogicalDecodingContext *ctx)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
void * MemoryContextAllocZero(MemoryContext context, Size size)
MemoryContext CurrentMemoryContext
void * repalloc(void *pointer, Size size)
void * MemoryContextAlloc(MemoryContext context, Size size)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define SLAB_DEFAULT_BLOCK_SIZE
#define CHECK_FOR_INTERRUPTS()
void pairingheap_remove(pairingheap *heap, pairingheap_node *node)
void pairingheap_add(pairingheap *heap, pairingheap_node *node)
pairingheap_node * pairingheap_first(pairingheap *heap)
pairingheap * pairingheap_allocate(pairingheap_comparator compare, void *arg)
#define pairingheap_container(type, membername, ptr)
#define pairingheap_const_container(type, membername, ptr)
FormData_pg_attribute * Form_pg_attribute