Skip to content

Commit

Permalink
Implement serverless file caching (disk or memory).
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 committed Jun 4, 2017
1 parent d7a0e42 commit f7400a4
Show file tree
Hide file tree
Showing 23 changed files with 1,584 additions and 610 deletions.
2 changes: 1 addition & 1 deletion src/XrdFileCache.cmake
Expand Up @@ -30,7 +30,7 @@ add_library(

target_link_libraries(
${LIB_XRD_FILECACHE}
XrdPosix
# XrdPosix
XrdCl
XrdUtils
XrdServer
Expand Down
24 changes: 17 additions & 7 deletions src/XrdFileCache/XrdFileCache.cc
Expand Up @@ -40,6 +40,8 @@ using namespace XrdFileCache;

Cache * Cache::m_factory = NULL;

XrdScheduler *Cache::schedP = NULL;


void *CacheDirCleanupThread(void* cache_void)
{
Expand All @@ -61,12 +63,6 @@ void *PrefetchThread(void* ptr)
return NULL;
}


namespace XrdPosixGlobals
{
extern XrdScheduler *schedP;
}

extern "C"
{
XrdOucCache2 *XrdOucGetCache2(XrdSysLogger *logger,
Expand Down Expand Up @@ -329,12 +325,26 @@ void Cache::ReleaseFile(File* f)
}

//______________________________________________________________________________

namespace
{
void *callDoIt(void *pp)
{
XrdJob *jP = (XrdJob *)pp;
jP->DoIt();
return (void *)0;
}
};

void Cache::schedule_file_sync(File* f, bool ref_cnt_already_set)
{
DiskSyncer* ds = new DiskSyncer(f);
if ( ! ref_cnt_already_set) inc_ref_cnt(f, true);
XrdPosixGlobals::schedP->Schedule(ds);
if (isClient) ds->DoIt();
else if (schedP) schedP->Schedule(ds);
else {pthread_t tid;
XrdSysThread::Run(&tid, callDoIt, ds, 0, "DiskSyncer");
}
}

//______________________________________________________________________________
Expand Down
7 changes: 7 additions & 0 deletions src/XrdFileCache/XrdFileCache.hh
Expand Up @@ -114,6 +114,10 @@ public:
//---------------------------------------------------------------------
virtual int isAttached();

//---------------------------------------------------------------------
// Virtual function of XrdOucCache2. Used to pass environmental info.
virtual void EnvInfo(XrdOucEnv &theEnv);

//---------------------------------------------------------------------
// Virtual function of XrdOucCache2. Used for deferred open.
virtual int Prepare(const char *url, int oflags, mode_t mode);
Expand Down Expand Up @@ -214,6 +218,8 @@ private:
bool xtrace(XrdOucStream &);

static Cache *m_factory; //!< this object
static
XrdScheduler *schedP;

XrdSysError m_log; //!< XrdFileCache namespace logger
XrdOucTrace *m_trace;
Expand All @@ -232,6 +238,7 @@ private:

XrdSysMutex m_RAMblock_mutex; //!< central lock for this class
int m_RAMblocks_used;
bool isClient; //!< True if running as client

struct WriteQ
{
Expand Down
19 changes: 15 additions & 4 deletions src/XrdFileCache/XrdFileCacheConfiguration.cc
Expand Up @@ -106,13 +106,14 @@ bool Cache::xtrace(XrdOucStream &Config)
bool Cache::Config(XrdSysLogger *logger, const char *config_filename, const char *parameters)
{
m_log.logger(logger);
const char *theINS = getenv("XRDINSTANCE");

const char * cache_env;
if (! (cache_env = getenv("XRDPOSIX_CACHE")) || ! *cache_env)
XrdOucEnv::Export("XRDPOSIX_CACHE", "mode=s&optwr=0");
// Indicate whether or not we are a client instance
//
isClient = (strncmp("*client ", theINS, 8) != 0);

XrdOucEnv myEnv;
XrdOucStream Config(&m_log, getenv("XRDINSTANCE"), &myEnv, "=====> ");
XrdOucStream Config(&m_log, theINS, &myEnv, "=====> ");

if (! config_filename || ! *config_filename)
{
Expand Down Expand Up @@ -418,3 +419,13 @@ bool Cache::ConfigParameters(std::string part, XrdOucStream& config, TmpConfigur

return true;
}

//______________________________________________________________________________


void Cache::EnvInfo(XrdOucEnv &theEnv)
{
// Extract out the pointer to the scheduler
//
schedP = (XrdScheduler *)theEnv.GetPtr("XrdScheduler*");
}
1 change: 0 additions & 1 deletion src/XrdFileCache/XrdFileCacheFile.cc
Expand Up @@ -33,7 +33,6 @@
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdSfs/XrdSfsInterface.hh"
#include "XrdFileCache.hh"
#include "Xrd/XrdScheduler.hh"


using namespace XrdFileCache;
Expand Down
13 changes: 13 additions & 0 deletions src/XrdOuc/XrdOucCache2.hh
Expand Up @@ -181,6 +181,7 @@ virtual ~XrdOucCacheIO2() {} // Always use Detach() instead of direct delete
/* C l a s s X r d O u c C a c h e 2 */
/******************************************************************************/

class XrdOucEnv;
struct stat;

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -230,6 +231,18 @@ virtual
XrdOucCache *Create(Parms &Params, XrdOucCacheIO::aprParms *aprP=0)
{return this;}

//------------------------------------------------------------------------------
//! Supply environmental information to the cache for optimization. This is
//! only called server-side but is optional and might not be called. The
//! environmental information should only be used for optimizations. When
//! called, it is gauranteed to occur before any active use of the cache and
//! is essentially serialized (i.e. the main start-up thread is used).
//!
//! @param theEnv - Reference to environmental information.
//------------------------------------------------------------------------------
virtual
void EnvInfo(XrdOucEnv &theEnv) {(void)theEnv;}

//------------------------------------------------------------------------------
//! Preapare the cache for a file open request. This method is called prior to
//! actually opening a file. This method is meant to allow defering an open
Expand Down

0 comments on commit f7400a4

Please sign in to comment.