Skip to content

Commit

Permalink
XrdApps::JCache: add a seperate handler for Read calls since the return
Browse files Browse the repository at this point in the history
object is different from PgRead (ChunkInfo vs PageInfo)
  • Loading branch information
Andreas Joachim Peters committed Jun 10, 2024
1 parent f6ca2c0 commit 28cf161
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ JCacheFile::Read(uint64_t offset,
}

auto jhandler = new JCacheReadHandler(handler, &pStats.bytesRead,sEnableJournalCache?&pJournal:nullptr);
pStats.readOps++;
st = pFile->PgRead(offset, size, buffer, jhandler, timeout);
pStats.readOps++;
st = pFile->Read(offset, size, buffer, jhandler, timeout);
} else {
st = XRootDStatus(stError, errInvalidOp);
}
Expand Down Expand Up @@ -227,7 +227,6 @@ JCacheFile::PgRead( uint64_t offset,
uint16_t timeout )
{
XRootDStatus st;

if (pFile) {
if (sEnableJournalCache && AttachForRead()) {
auto rb = pJournal.pread(buffer, size, offset);
Expand All @@ -245,8 +244,8 @@ JCacheFile::PgRead( uint64_t offset,
}
}

auto jhandler = new JCacheReadHandler(handler, &pStats.bytesRead,sEnableJournalCache?&pJournal:nullptr);
pStats.readOps++;
auto jhandler = new JCachePgReadHandler(handler, &pStats.bytesRead,sEnableJournalCache?&pJournal:nullptr);
pStats.readOps++;
st = pFile->PgRead(offset, size, buffer, jhandler, timeout);
} else {
st = XRootDStatus(stError, errInvalidOp);
Expand Down
3 changes: 2 additions & 1 deletion src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "cache/Journal.hh"
#include "vector/XrdClVectorCache.hh"
#include "handler/XrdClJCacheReadHandler.hh"
#include "handler/XrdClJCachePgReadHandler.hh"
#include "handler/XrdClJCacheReadVHandler.hh"
/*----------------------------------------------------------------------------*/
#include <atomic>
Expand Down Expand Up @@ -330,4 +331,4 @@ private:
CacheStats pStats;
};

} // namespace XrdCl
} // namespace XrdCl
72 changes: 72 additions & 0 deletions src/XrdApps/XrdClJCachePlugin/handler/XrdClJCachePgReadHandler.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//------------------------------------------------------------------------------
// Copyright (c) 2024 by European Organization for Nuclear Research (CERN)
// Author: Andreas-Joachim Peters <[email protected]>
//------------------------------------------------------------------------------
// This file is part of the XRootD software suite.
//
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//
// In applying this licence, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#pragma once
/*----------------------------------------------------------------------------*/
#include "XrdCl/XrdClFile.hh"
#include "XrdCl/XrdClXRootDResponses.hh"
/*----------------------------------------------------------------------------*/
#include "cache/Journal.hh"
/*----------------------------------------------------------------------------*/

namespace XrdCl {

class JCachePgReadHandler : public XrdCl::ResponseHandler
// ---------------------------------------------------------------------- //
{
public:
JCachePgReadHandler() { }

JCachePgReadHandler(JCacheReadHandler* other) {
rbytes = other->rbytes;
journal = other->journal;
}

JCachePgReadHandler(XrdCl::ResponseHandler* handler,
std::atomic<uint64_t>* rbytes,
Journal* journal) : handler(handler), rbytes(rbytes), journal(journal) {}

virtual ~JCachePgReadHandler() {}

virtual void HandleResponse(XrdCl::XRootDStatus* pStatus,
XrdCl::AnyObject* pResponse) {

XrdCl::PageInfo* pageInfo;
if (pStatus->IsOK()) {
if (pResponse) {
pResponse->Get(pageInfo);
// store successfull reads in the journal
if (journal) journal->pwrite(pageInfo->GetBuffer(), pageInfo->GetLength(), pageInfo->GetOffset());
*rbytes+= pageInfo->GetLength();
}
}
handler->HandleResponse(pStatus, pResponse);
}

XrdCl::ResponseHandler* handler;
std::atomic<uint64_t>* rbytes;
Journal* journal;

};

} // namespace XrdCl
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public:
virtual void HandleResponse(XrdCl::XRootDStatus* pStatus,
XrdCl::AnyObject* pResponse) {

XrdCl::PageInfo* pageInfo;
XrdCl::ChunkInfo* chunkInfo;
if (pStatus->IsOK()) {
if (pResponse) {
pResponse->Get(pageInfo);
pResponse->Get(chunkInfo);
// store successfull reads in the journal
if (journal) journal->pwrite(pageInfo->GetBuffer(), pageInfo->GetLength(), pageInfo->GetOffset());
*rbytes+= pageInfo->GetLength();
if (journal) journal->pwrite(chunkInfo->GetBuffer(), chunkInfo->GetLength(), chunkInfo->GetOffset());
*rbytes+= chunkInfo->GetLength();
}
}
handler->HandleResponse(pStatus, pResponse);
Expand Down

0 comments on commit 28cf161

Please sign in to comment.