1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-06-18 23:57:33 +02:00

storageFileRead() accepts a buffer for output rather than creating one.

This is more efficient overall and allows the caller to specify how many bytes will be read on each call. Reads are appended if the buffer already contains data but the buffer size will never increase.

Allow Buffer object "used size" to be different than "allocated size". Add functions to manage used size and remaining size and update automatically when possible.
This commit is contained in:
David Steele
2018-07-17 19:01:54 -04:00
parent 0acf705416
commit 5dc8a2ec08
17 changed files with 362 additions and 115 deletions

View File

@ -9,6 +9,12 @@ PostgreSQL Info
#include "postgres/version.h"
#include "storage/helper.h"
/***********************************************************************************************************************************
Set control data size. The control file is actually 8192 bytes but only the first 512 bytes are used to prevent torn pages even on
really old storage with 512-byte sectors.
***********************************************************************************************************************************/
#define PG_CONTROL_DATA_SIZE 512
/***********************************************************************************************************************************
Map control/catalog version to PostgreSQL version
***********************************************************************************************************************************/
@ -72,15 +78,13 @@ pgControlInfo(const String *pgPath)
MEM_CONTEXT_TEMP_BEGIN()
{
// Open control file for read
StorageFileRead *controlRead = storageNewReadNP(
storageLocal(), strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strPtr(pgPath)));
storageFileReadOpen(controlRead);
// Read control file
PgControlFile *control = (PgControlFile *)bufPtr(
storageGetP(
storageNewReadNP(storageLocal(), strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strPtr(pgPath))),
.exactSize = PG_CONTROL_DATA_SIZE));
// Read contents
PgControlFile *control = (PgControlFile *)bufPtr(storageFileRead(controlRead));
// Copy to result structure and get PostgreSQL version
// Get PostgreSQL version
result.systemId = control->systemId;
result.controlVersion = control->controlVersion;
result.catalogVersion = control->catalogVersion;