2
0

logtape.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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-2022, 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. #ifndef LOGTAPE_H
  16. #define LOGTAPE_H
  17. #include "storage/sharedfileset.h"
  18. /*
  19. * LogicalTapeSet and LogicalTape are opaque types whose details are not
  20. * known outside logtape.c.
  21. */
  22. typedef struct LogicalTapeSet LogicalTapeSet;
  23. typedef struct LogicalTape LogicalTape;
  24. /*
  25. * The approach tuplesort.c takes to parallel external sorts is that workers,
  26. * whose state is almost the same as independent serial sorts, are made to
  27. * produce a final materialized tape of sorted output in all cases. This is
  28. * frozen, just like any case requiring a final materialized tape. However,
  29. * there is one difference, which is that freezing will also export an
  30. * underlying shared fileset BufFile for sharing. Freezing produces TapeShare
  31. * metadata for the worker when this happens, which is passed along through
  32. * shared memory to leader.
  33. *
  34. * The leader process can then pass an array of TapeShare metadata (one per
  35. * worker participant) to LogicalTapeSetCreate(), alongside a handle to a
  36. * shared fileset, which is sufficient to construct a new logical tapeset that
  37. * consists of each of the tapes materialized by workers.
  38. *
  39. * Note that while logtape.c does create an empty leader tape at the end of the
  40. * tapeset in the leader case, it can never be written to due to a restriction
  41. * in the shared buffile infrastructure.
  42. */
  43. typedef struct TapeShare
  44. {
  45. /*
  46. * Currently, all the leader process needs is the location of the
  47. * materialized tape's first block.
  48. */
  49. long firstblocknumber;
  50. } TapeShare;
  51. /*
  52. * prototypes for functions in logtape.c
  53. */
  54. extern LogicalTapeSet *LogicalTapeSetCreate(bool preallocate,
  55. SharedFileSet *fileset, int worker);
  56. extern void LogicalTapeClose(LogicalTape *lt);
  57. extern void LogicalTapeSetClose(LogicalTapeSet *lts);
  58. extern LogicalTape *LogicalTapeCreate(LogicalTapeSet *lts);
  59. extern LogicalTape *LogicalTapeImport(LogicalTapeSet *lts, int worker, TapeShare *shared);
  60. extern void LogicalTapeSetForgetFreeSpace(LogicalTapeSet *lts);
  61. extern size_t LogicalTapeRead(LogicalTape *lt, void *ptr, size_t size);
  62. extern void LogicalTapeWrite(LogicalTape *lt, void *ptr, size_t size);
  63. extern void LogicalTapeRewindForRead(LogicalTape *lt, size_t buffer_size);
  64. extern void LogicalTapeFreeze(LogicalTape *lt, TapeShare *share);
  65. extern size_t LogicalTapeBackspace(LogicalTape *lt, size_t size);
  66. extern void LogicalTapeSeek(LogicalTape *lt, long blocknum, int offset);
  67. extern void LogicalTapeTell(LogicalTape *lt, long *blocknum, int *offset);
  68. extern long LogicalTapeSetBlocks(LogicalTapeSet *lts);
  69. #endif /* LOGTAPE_H */