static void * readtup_heap(Tuplestorestate *state, unsigned int len) { void *tup = NULL; uint32 tuplen = 0; if (is_len_memtuplen(len)) { tuplen = memtuple_size_from_uint32(len); } else { /* len is HeapTuple.t_len. The record size includes rest of the HeapTuple fields */ tuplen = len + HEAPTUPLESIZE; } tup = (void *) palloc(tuplen); USEMEM(state, GetMemoryChunkSpace(tup)); if(is_len_memtuplen(len)) { /* read in the tuple proper */ memtuple_set_mtlen((MemTuple) tup, len); if (BufFileRead(state->myfile, (void *) ((char *) tup + sizeof(uint32)), tuplen - sizeof(uint32)) != (size_t) (tuplen - sizeof(uint32))) { insist_log(false, "unexpected end of data"); } } else { HeapTuple htup = (HeapTuple) tup; htup->t_len = tuplen - HEAPTUPLESIZE; if (BufFileRead(state->myfile, (void *) ((char *) tup + sizeof(uint32)), tuplen - sizeof(uint32)) != (size_t) (tuplen - sizeof(uint32))) { insist_log(false, "unexpected end of data"); } htup->t_data = (HeapTupleHeader ) ((char *) tup + HEAPTUPLESIZE); } if (state->backward) /* need trailing length word? */ { if (BufFileRead(state->myfile, (void *) &tuplen, sizeof(tuplen)) != sizeof(tuplen)) { insist_log(false, "unexpected end of data"); } } return (void *) tup; }
/* * Read a block-sized buffer from the specified block of the underlying file. * * No need for an error return convention; we ereport() on any error. This * module should never attempt to read a block it doesn't know is there. */ static void ltsReadBlock(LogicalTapeSet *lts, long blocknum, void *buffer) { if (BufFileSeekBlock(lts->pfile, blocknum) != 0 || BufFileRead(lts->pfile, buffer, BLCKSZ) != BLCKSZ) ereport(ERROR, (errcode_for_file_access(), errmsg("could not read block %ld of temporary file: %m", blocknum))); }
static void * readtup_heap(Tuplestorestate *state, unsigned int len) { unsigned int tupbodylen = len - sizeof(int); unsigned int tuplen = tupbodylen + MINIMAL_TUPLE_DATA_OFFSET; MinimalTuple tuple = (MinimalTuple) palloc(tuplen); char *tupbody = (char *) tuple + MINIMAL_TUPLE_DATA_OFFSET; USEMEM(state, GetMemoryChunkSpace(tuple)); /* read in the tuple proper */ tuple->t_len = tuplen; if (BufFileRead(state->myfile, (void *) tupbody, tupbodylen) != (size_t) tupbodylen) elog(ERROR, "unexpected end of data"); if (state->backward) /* need trailing length word? */ if (BufFileRead(state->myfile, (void *) &tuplen, sizeof(tuplen)) != sizeof(tuplen)) elog(ERROR, "unexpected end of data"); return (void *) tuple; }
static uint32 getlen(Tuplestorestate *state, TuplestorePos *pos, bool eofOK) { uint32 len; size_t nbytes; nbytes = BufFileRead(state->myfile, (void *) &len, sizeof(len)); if (nbytes == sizeof(len)) return len; insist_log(nbytes == 0, "unexpected end of tape"); insist_log(eofOK, "unexpected end of data"); return 0; }
static void * readtup_heap(Tuplestorestate *state, unsigned int len) { unsigned int tupbodylen = len - sizeof(int); unsigned int tuplen = tupbodylen + MINIMAL_TUPLE_DATA_OFFSET; MinimalTuple tuple = (MinimalTuple) palloc(tuplen); char *tupbody = (char *) tuple + MINIMAL_TUPLE_DATA_OFFSET; USEMEM(state, GetMemoryChunkSpace(tuple)); /* read in the tuple proper */ tuple->t_len = tuplen; if (BufFileRead(state->myfile, (void *) tupbody, tupbodylen) != (size_t) tupbodylen) ereport(ERROR, (errcode_for_file_access(), errmsg("could not read from tuplestore temporary file: %m"))); if (state->backward) /* need trailing length word? */ if (BufFileRead(state->myfile, (void *) &tuplen, sizeof(tuplen)) != sizeof(tuplen)) ereport(ERROR, (errcode_for_file_access(), errmsg("could not read from tuplestore temporary file: %m"))); return (void *) tuple; }
static unsigned int getlen(Tuplestorestate *state, bool eofOK) { unsigned int len; size_t nbytes; nbytes = BufFileRead(state->myfile, (void *) &len, sizeof(len)); if (nbytes == sizeof(len)) return len; if (nbytes != 0 || !eofOK) ereport(ERROR, (errcode_for_file_access(), errmsg("could not read from tuplestore temporary file: %m"))); return 0; }
static unsigned int getlen(Tuplestorestate *state, bool eofOK) { unsigned int len; size_t nbytes; nbytes = BufFileRead(state->myfile, (void *) &len, sizeof(len)); if (nbytes == sizeof(len)) return len; if (nbytes != 0) elog(ERROR, "unexpected end of tape"); if (!eofOK) elog(ERROR, "unexpected end of data"); return 0; }
/* * ExecWorkFile_Read * read the data with specified size to the given buffer. * * The given buffer should contain at least the space specified by * 'size'. * * If the read succeeds, this function returns the number of bytes * that are read. Otherwise, returns 0. */ uint64 ExecWorkFile_Read(ExecWorkFile *workfile, void *data, uint64 size) { Assert(workfile != NULL); uint64 bytes = 0; switch(workfile->fileType) { case BUFFILE: bytes = BufFileRead((BufFile *)workfile->file, data, size); break; case BFZ: bytes = bfz_scan_next((bfz_t *)workfile->file, data, size); break; default: insist_log(false, "invalid work file type: %d", workfile->fileType); } return bytes; }
void loadSharedComboCommandId(TransactionId xmin, CommandId combocid, CommandId *cmin, CommandId *cmax) { bool found = false; ComboCidEntryData entry; int i; Assert(Gp_role == GP_ROLE_EXECUTE); Assert(!Gp_is_writer); Assert(cmin != NULL); Assert(cmax != NULL); if (lockHolderProcPtr == NULL) { /* get lockholder! */ elog(ERROR, "loadSharedComboCommandId: NO LOCK HOLDER POINTER."); } if (combocid_map == NULL) { MemoryContext oldCtx; char path[MAXPGPATH]; ComboCidMapName(path, gp_session_id, lockHolderProcPtr->pid); /* open our file, as appropriate: this will throw an error if the create-fails. */ oldCtx = MemoryContextSwitchTo(TopMemoryContext); combocid_map = BufFileCreateTemp_ReaderWriter(path, false, true); MemoryContextSwitchTo(oldCtx); } Assert(combocid_map != NULL); /* Seek to the beginning to start our search ? */ if (BufFileSeek(combocid_map, 0 /* fileno */, 0 /* offset */, SEEK_SET) != 0) { elog(ERROR, "loadSharedComboCommandId: seek to beginning failed."); } /* * Read this entry in ... * * We're going to read in the entire table, caching all occurrences of * our xmin. */ for (i = 0; i < lockHolderProcPtr->combocid_map_count; i++) { if (BufFileRead(combocid_map, &entry, sizeof(ComboCidEntryData)) != sizeof(ComboCidEntryData)) { elog(ERROR, "loadSharedComboCommandId: read failed I/O error."); } if (entry.key.xmin == xmin) { bool cached = false; readerComboCidKeyData reader_key; readerComboCidEntryData *reader_entry; memset(&reader_key, 0, sizeof(reader_key)); reader_key.writer_pid = lockHolderProcPtr->pid; reader_key.xmin = entry.key.xmin; reader_key.session = gp_session_id; reader_key.combocid = entry.combocid; reader_entry = (readerComboCidEntryData *) hash_search(readerComboHash, &reader_key, HASH_ENTER, &cached); if (!cached) { reader_entry->cmin = entry.key.cmin; reader_entry->cmax = entry.key.cmax; } /* * This was our entry -- we're going to continue our scan, * to pull in any additional entries for our xmin */ if (entry.combocid == combocid) { *cmin = entry.key.cmin; *cmax = entry.key.cmax; found = true; } } } if (!found) { elog(ERROR, "loadSharedComboCommandId: no combocid entry found for %u/%u", xmin, combocid); } }