diff --git a/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.cc b/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.cc index cc560764453..16941f66135 100644 --- a/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.cc +++ b/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.cc @@ -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); } @@ -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); @@ -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); diff --git a/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.hh b/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.hh index 504934201b9..29f0288ce26 100644 --- a/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.hh +++ b/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.hh @@ -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 @@ -330,4 +331,4 @@ private: CacheStats pStats; }; -} // namespace XrdCl \ No newline at end of file +} // namespace XrdCl diff --git a/src/XrdApps/XrdClJCachePlugin/handler/XrdClJCachePgReadHandler.hh b/src/XrdApps/XrdClJCachePlugin/handler/XrdClJCachePgReadHandler.hh new file mode 100644 index 00000000000..a5ae639461e --- /dev/null +++ b/src/XrdApps/XrdClJCachePlugin/handler/XrdClJCachePgReadHandler.hh @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2024 by European Organization for Nuclear Research (CERN) +// Author: Andreas-Joachim Peters +//------------------------------------------------------------------------------ +// 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 . +// +// 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* 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* rbytes; + Journal* journal; + +}; + +} // namespace XrdCl diff --git a/src/XrdApps/XrdClJCachePlugin/handler/XrdClJCacheReadHandler.hh b/src/XrdApps/XrdClJCachePlugin/handler/XrdClJCacheReadHandler.hh index f2a2727a6a4..dd6a3814b79 100644 --- a/src/XrdApps/XrdClJCachePlugin/handler/XrdClJCacheReadHandler.hh +++ b/src/XrdApps/XrdClJCachePlugin/handler/XrdClJCacheReadHandler.hh @@ -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);