Skip to content

Commit

Permalink
Move storageReadRemoteOpen() in storage/remote/read module.
Browse files Browse the repository at this point in the history
This will make an upcoming important fix easier to review.
  • Loading branch information
dwsteele committed Oct 13, 2022
1 parent 909be41 commit ea162e8
Showing 1 changed file with 62 additions and 62 deletions.
124 changes: 62 additions & 62 deletions src/storage/remote/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,68 +43,6 @@ Macros for function logging
#define FUNCTION_LOG_STORAGE_READ_REMOTE_FORMAT(value, buffer, bufferSize) \
objToLog(value, "StorageReadRemote", buffer, bufferSize)

/***********************************************************************************************************************************
Open the file
***********************************************************************************************************************************/
static bool
storageReadRemoteOpen(THIS_VOID)
{
THIS(StorageReadRemote);

FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(STORAGE_READ_REMOTE, this);
FUNCTION_LOG_END();

ASSERT(this != NULL);

bool result = false;

MEM_CONTEXT_TEMP_BEGIN()
{
// If the file is compressible add compression filter on the remote
if (this->interface.compressible)
{
ioFilterGroupAdd(
ioReadFilterGroup(storageReadIo(this->read)), compressFilter(compressTypeGz, (int)this->interface.compressLevel));
}

ProtocolCommand *command = protocolCommandNew(PROTOCOL_COMMAND_STORAGE_OPEN_READ);
PackWrite *const param = protocolCommandParam(command);

pckWriteStrP(param, this->interface.name);
pckWriteBoolP(param, this->interface.ignoreMissing);
pckWriteU64P(param, this->interface.offset);

if (this->interface.limit == NULL)
pckWriteNullP(param);
else
pckWriteU64P(param, varUInt64(this->interface.limit));

pckWritePackP(param, ioFilterGroupParamAll(ioReadFilterGroup(storageReadIo(this->read))));

protocolClientCommandPut(this->client, command, false);

// If the file exists
result = pckReadBoolP(protocolClientDataGet(this->client));

if (result)
{
// Clear filters since they will be run on the remote side
ioFilterGroupClear(ioReadFilterGroup(storageReadIo(this->read)));

// If the file is compressible add decompression filter locally
if (this->interface.compressible)
ioFilterGroupAdd(ioReadFilterGroup(storageReadIo(this->read)), decompressFilter(compressTypeGz));
}
// Else nothing to do
else
protocolClientDataEndGet(this->client);
}
MEM_CONTEXT_TEMP_END();

FUNCTION_LOG_RETURN(BOOL, result);
}

/***********************************************************************************************************************************
Read from a file
***********************************************************************************************************************************/
Expand Down Expand Up @@ -209,6 +147,68 @@ storageReadRemoteEof(THIS_VOID)
FUNCTION_TEST_RETURN(BOOL, this->eof);
}

/***********************************************************************************************************************************
Open the file
***********************************************************************************************************************************/
static bool
storageReadRemoteOpen(THIS_VOID)
{
THIS(StorageReadRemote);

FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(STORAGE_READ_REMOTE, this);
FUNCTION_LOG_END();

ASSERT(this != NULL);

bool result = false;

MEM_CONTEXT_TEMP_BEGIN()
{
// If the file is compressible add compression filter on the remote
if (this->interface.compressible)
{
ioFilterGroupAdd(
ioReadFilterGroup(storageReadIo(this->read)), compressFilter(compressTypeGz, (int)this->interface.compressLevel));
}

ProtocolCommand *command = protocolCommandNew(PROTOCOL_COMMAND_STORAGE_OPEN_READ);
PackWrite *const param = protocolCommandParam(command);

pckWriteStrP(param, this->interface.name);
pckWriteBoolP(param, this->interface.ignoreMissing);
pckWriteU64P(param, this->interface.offset);

if (this->interface.limit == NULL)
pckWriteNullP(param);
else
pckWriteU64P(param, varUInt64(this->interface.limit));

pckWritePackP(param, ioFilterGroupParamAll(ioReadFilterGroup(storageReadIo(this->read))));

protocolClientCommandPut(this->client, command, false);

// If the file exists
result = pckReadBoolP(protocolClientDataGet(this->client));

if (result)
{
// Clear filters since they will be run on the remote side
ioFilterGroupClear(ioReadFilterGroup(storageReadIo(this->read)));

// If the file is compressible add decompression filter locally
if (this->interface.compressible)
ioFilterGroupAdd(ioReadFilterGroup(storageReadIo(this->read)), decompressFilter(compressTypeGz));
}
// Else nothing to do
else
protocolClientDataEndGet(this->client);
}
MEM_CONTEXT_TEMP_END();

FUNCTION_LOG_RETURN(BOOL, result);
}

/**********************************************************************************************************************************/
StorageRead *
storageReadRemoteNew(
Expand Down

0 comments on commit ea162e8

Please sign in to comment.