1999-10-16 15:49:28 -04:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* logtape.h
|
|
|
|
|
* Management of "logical tapes" within temporary files.
|
|
|
|
|
*
|
|
|
|
|
* See logtape.c for explanations.
|
|
|
|
|
*
|
2022-01-07 19:04:57 -05:00
|
|
|
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
|
2000-01-26 00:58:53 -05:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1999-10-16 15:49:28 -04:00
|
|
|
*
|
2010-09-20 16:08:53 -04:00
|
|
|
* src/include/utils/logtape.h
|
1999-10-16 15:49:28 -04:00
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef LOGTAPE_H
|
|
|
|
|
#define LOGTAPE_H
|
|
|
|
|
|
Support parallel btree index builds.
To make this work, tuplesort.c and logtape.c must also support
parallelism, so this patch adds that infrastructure and then applies
it to the particular case of parallel btree index builds. Testing
to date shows that this can often be 2-3x faster than a serial
index build.
The model for deciding how many workers to use is fairly primitive
at present, but it's better than not having the feature. We can
refine it as we get more experience.
Peter Geoghegan with some help from Rushabh Lathia. While Heikki
Linnakangas is not an author of this patch, he wrote other patches
without which this feature would not have been possible, and
therefore the release notes should possibly credit him as an author
of this feature. Reviewed by Claudio Freire, Heikki Linnakangas,
Thomas Munro, Tels, Amit Kapila, me.
Discussion: http://postgr.es/m/CAM3SWZQKM=Pzc=CAHzRixKjp2eO5Q0Jg1SoFQqeXFQ647JiwqQ@mail.gmail.com
Discussion: http://postgr.es/m/CAH2-Wz=AxWqDoVvGU7dq856S4r6sJAj6DBn7VMtigkB33N5eyg@mail.gmail.com
2018-02-02 13:25:55 -05:00
|
|
|
#include "storage/sharedfileset.h"
|
|
|
|
|
|
2021-10-18 07:30:00 -04:00
|
|
|
/*
|
|
|
|
|
* LogicalTapeSet and LogicalTape are opaque types whose details are not
|
|
|
|
|
* known outside logtape.c.
|
|
|
|
|
*/
|
1999-10-16 15:49:28 -04:00
|
|
|
typedef struct LogicalTapeSet LogicalTapeSet;
|
2021-10-18 07:30:00 -04:00
|
|
|
typedef struct LogicalTape LogicalTape;
|
|
|
|
|
|
1999-10-16 15:49:28 -04:00
|
|
|
|
Support parallel btree index builds.
To make this work, tuplesort.c and logtape.c must also support
parallelism, so this patch adds that infrastructure and then applies
it to the particular case of parallel btree index builds. Testing
to date shows that this can often be 2-3x faster than a serial
index build.
The model for deciding how many workers to use is fairly primitive
at present, but it's better than not having the feature. We can
refine it as we get more experience.
Peter Geoghegan with some help from Rushabh Lathia. While Heikki
Linnakangas is not an author of this patch, he wrote other patches
without which this feature would not have been possible, and
therefore the release notes should possibly credit him as an author
of this feature. Reviewed by Claudio Freire, Heikki Linnakangas,
Thomas Munro, Tels, Amit Kapila, me.
Discussion: http://postgr.es/m/CAM3SWZQKM=Pzc=CAHzRixKjp2eO5Q0Jg1SoFQqeXFQ647JiwqQ@mail.gmail.com
Discussion: http://postgr.es/m/CAH2-Wz=AxWqDoVvGU7dq856S4r6sJAj6DBn7VMtigkB33N5eyg@mail.gmail.com
2018-02-02 13:25:55 -05:00
|
|
|
/*
|
|
|
|
|
* The approach tuplesort.c takes to parallel external sorts is that workers,
|
|
|
|
|
* whose state is almost the same as independent serial sorts, are made to
|
|
|
|
|
* produce a final materialized tape of sorted output in all cases. This is
|
|
|
|
|
* frozen, just like any case requiring a final materialized tape. However,
|
|
|
|
|
* there is one difference, which is that freezing will also export an
|
|
|
|
|
* underlying shared fileset BufFile for sharing. Freezing produces TapeShare
|
|
|
|
|
* metadata for the worker when this happens, which is passed along through
|
|
|
|
|
* shared memory to leader.
|
|
|
|
|
*
|
|
|
|
|
* The leader process can then pass an array of TapeShare metadata (one per
|
|
|
|
|
* worker participant) to LogicalTapeSetCreate(), alongside a handle to a
|
|
|
|
|
* shared fileset, which is sufficient to construct a new logical tapeset that
|
|
|
|
|
* consists of each of the tapes materialized by workers.
|
|
|
|
|
*
|
|
|
|
|
* Note that while logtape.c does create an empty leader tape at the end of the
|
|
|
|
|
* tapeset in the leader case, it can never be written to due to a restriction
|
|
|
|
|
* in the shared buffile infrastructure.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct TapeShare
|
|
|
|
|
{
|
|
|
|
|
/*
|
2018-05-02 10:23:13 -04:00
|
|
|
* Currently, all the leader process needs is the location of the
|
|
|
|
|
* materialized tape's first block.
|
Support parallel btree index builds.
To make this work, tuplesort.c and logtape.c must also support
parallelism, so this patch adds that infrastructure and then applies
it to the particular case of parallel btree index builds. Testing
to date shows that this can often be 2-3x faster than a serial
index build.
The model for deciding how many workers to use is fairly primitive
at present, but it's better than not having the feature. We can
refine it as we get more experience.
Peter Geoghegan with some help from Rushabh Lathia. While Heikki
Linnakangas is not an author of this patch, he wrote other patches
without which this feature would not have been possible, and
therefore the release notes should possibly credit him as an author
of this feature. Reviewed by Claudio Freire, Heikki Linnakangas,
Thomas Munro, Tels, Amit Kapila, me.
Discussion: http://postgr.es/m/CAM3SWZQKM=Pzc=CAHzRixKjp2eO5Q0Jg1SoFQqeXFQ647JiwqQ@mail.gmail.com
Discussion: http://postgr.es/m/CAH2-Wz=AxWqDoVvGU7dq856S4r6sJAj6DBn7VMtigkB33N5eyg@mail.gmail.com
2018-02-02 13:25:55 -05:00
|
|
|
*/
|
|
|
|
|
long firstblocknumber;
|
|
|
|
|
} TapeShare;
|
|
|
|
|
|
1999-10-16 15:49:28 -04:00
|
|
|
/*
|
|
|
|
|
* prototypes for functions in logtape.c
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-18 07:30:00 -04:00
|
|
|
extern LogicalTapeSet *LogicalTapeSetCreate(bool preallocate,
|
Support parallel btree index builds.
To make this work, tuplesort.c and logtape.c must also support
parallelism, so this patch adds that infrastructure and then applies
it to the particular case of parallel btree index builds. Testing
to date shows that this can often be 2-3x faster than a serial
index build.
The model for deciding how many workers to use is fairly primitive
at present, but it's better than not having the feature. We can
refine it as we get more experience.
Peter Geoghegan with some help from Rushabh Lathia. While Heikki
Linnakangas is not an author of this patch, he wrote other patches
without which this feature would not have been possible, and
therefore the release notes should possibly credit him as an author
of this feature. Reviewed by Claudio Freire, Heikki Linnakangas,
Thomas Munro, Tels, Amit Kapila, me.
Discussion: http://postgr.es/m/CAM3SWZQKM=Pzc=CAHzRixKjp2eO5Q0Jg1SoFQqeXFQ647JiwqQ@mail.gmail.com
Discussion: http://postgr.es/m/CAH2-Wz=AxWqDoVvGU7dq856S4r6sJAj6DBn7VMtigkB33N5eyg@mail.gmail.com
2018-02-02 13:25:55 -05:00
|
|
|
SharedFileSet *fileset, int worker);
|
2021-10-18 07:30:00 -04:00
|
|
|
extern void LogicalTapeClose(LogicalTape *lt);
|
1999-10-16 15:49:28 -04:00
|
|
|
extern void LogicalTapeSetClose(LogicalTapeSet *lts);
|
2021-10-18 07:30:00 -04:00
|
|
|
extern LogicalTape *LogicalTapeCreate(LogicalTapeSet *lts);
|
|
|
|
|
extern LogicalTape *LogicalTapeImport(LogicalTapeSet *lts, int worker, TapeShare *shared);
|
2006-03-07 14:06:50 -05:00
|
|
|
extern void LogicalTapeSetForgetFreeSpace(LogicalTapeSet *lts);
|
2021-10-18 07:30:00 -04:00
|
|
|
extern size_t LogicalTapeRead(LogicalTape *lt, void *ptr, size_t size);
|
|
|
|
|
extern void LogicalTapeWrite(LogicalTape *lt, void *ptr, size_t size);
|
|
|
|
|
extern void LogicalTapeRewindForRead(LogicalTape *lt, size_t buffer_size);
|
|
|
|
|
extern void LogicalTapeFreeze(LogicalTape *lt, TapeShare *share);
|
|
|
|
|
extern size_t LogicalTapeBackspace(LogicalTape *lt, size_t size);
|
|
|
|
|
extern void LogicalTapeSeek(LogicalTape *lt, long blocknum, int offset);
|
|
|
|
|
extern void LogicalTapeTell(LogicalTape *lt, long *blocknum, int *offset);
|
2005-10-18 18:59:37 -04:00
|
|
|
extern long LogicalTapeSetBlocks(LogicalTapeSet *lts);
|
2001-10-28 01:26:15 -05:00
|
|
|
|
1999-10-16 15:49:28 -04:00
|
|
|
#endif /* LOGTAPE_H */
|