PostgreSQL Source Code  git master
logtape.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * logtape.h
4  * Management of "logical tapes" within temporary files.
5  *
6  * See logtape.c for explanations.
7  *
8  * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
9  * Portions Copyright (c) 1994, Regents of the University of California
10  *
11  * src/include/utils/logtape.h
12  *
13  *-------------------------------------------------------------------------
14  */
15 
16 #ifndef LOGTAPE_H
17 #define LOGTAPE_H
18 
19 #include "storage/sharedfileset.h"
20 
21 /* LogicalTapeSet is an opaque type whose details are not known outside logtape.c. */
22 
24 
25 /*
26  * The approach tuplesort.c takes to parallel external sorts is that workers,
27  * whose state is almost the same as independent serial sorts, are made to
28  * produce a final materialized tape of sorted output in all cases. This is
29  * frozen, just like any case requiring a final materialized tape. However,
30  * there is one difference, which is that freezing will also export an
31  * underlying shared fileset BufFile for sharing. Freezing produces TapeShare
32  * metadata for the worker when this happens, which is passed along through
33  * shared memory to leader.
34  *
35  * The leader process can then pass an array of TapeShare metadata (one per
36  * worker participant) to LogicalTapeSetCreate(), alongside a handle to a
37  * shared fileset, which is sufficient to construct a new logical tapeset that
38  * consists of each of the tapes materialized by workers.
39  *
40  * Note that while logtape.c does create an empty leader tape at the end of the
41  * tapeset in the leader case, it can never be written to due to a restriction
42  * in the shared buffile infrastructure.
43  */
44 typedef struct TapeShare
45 {
46  /*
47  * firstblocknumber is first block that should be read from materialized
48  * tape.
49  *
50  * buffilesize is the size of associated BufFile following freezing.
51  */
53  off_t buffilesize;
54 } TapeShare;
55 
56 /*
57  * prototypes for functions in logtape.c
58  */
59 
60 extern LogicalTapeSet *LogicalTapeSetCreate(int ntapes, TapeShare *shared,
61  SharedFileSet *fileset, int worker);
62 extern void LogicalTapeSetClose(LogicalTapeSet *lts);
64 extern size_t LogicalTapeRead(LogicalTapeSet *lts, int tapenum,
65  void *ptr, size_t size);
66 extern void LogicalTapeWrite(LogicalTapeSet *lts, int tapenum,
67  void *ptr, size_t size);
68 extern void LogicalTapeRewindForRead(LogicalTapeSet *lts, int tapenum,
69  size_t buffer_size);
70 extern void LogicalTapeRewindForWrite(LogicalTapeSet *lts, int tapenum);
71 extern void LogicalTapeFreeze(LogicalTapeSet *lts, int tapenum,
72  TapeShare *share);
73 extern size_t LogicalTapeBackspace(LogicalTapeSet *lts, int tapenum,
74  size_t size);
75 extern void LogicalTapeSeek(LogicalTapeSet *lts, int tapenum,
76  long blocknum, int offset);
77 extern void LogicalTapeTell(LogicalTapeSet *lts, int tapenum,
78  long *blocknum, int *offset);
79 extern long LogicalTapeSetBlocks(LogicalTapeSet *lts);
80 
81 #endif /* LOGTAPE_H */
long LogicalTapeSetBlocks(LogicalTapeSet *lts)
Definition: logtape.c:1070
off_t buffilesize
Definition: logtape.h:53
void LogicalTapeFreeze(LogicalTapeSet *lts, int tapenum, TapeShare *share)
Definition: logtape.c:863
long firstblocknumber
Definition: logtape.h:52
void LogicalTapeWrite(LogicalTapeSet *lts, int tapenum, void *ptr, size_t size)
Definition: logtape.c:620
void LogicalTapeSetClose(LogicalTapeSet *lts)
Definition: logtape.c:583
void LogicalTapeSeek(LogicalTapeSet *lts, int tapenum, long blocknum, int offset)
Definition: logtape.c:1019
void LogicalTapeSetForgetFreeSpace(LogicalTapeSet *lts)
Definition: logtape.c:609
struct TapeShare TapeShare
void LogicalTapeTell(LogicalTapeSet *lts, int tapenum, long *blocknum, int *offset)
Definition: logtape.c:1050
size_t LogicalTapeBackspace(LogicalTapeSet *lts, int tapenum, size_t size)
Definition: logtape.c:948
size_t LogicalTapeRead(LogicalTapeSet *lts, int tapenum, void *ptr, size_t size)
Definition: logtape.c:809
void LogicalTapeRewindForRead(LogicalTapeSet *lts, int tapenum, size_t buffer_size)
Definition: logtape.c:708
void LogicalTapeRewindForWrite(LogicalTapeSet *lts, int tapenum)
Definition: logtape.c:783
LogicalTapeSet * LogicalTapeSetCreate(int ntapes, TapeShare *shared, SharedFileSet *fileset, int worker)
Definition: logtape.c:509