41 #include <type_traits>
42 #include <system_error>
66 switch(desired_state) {
141 const size_t max_key { 120 };
143 const size_t flangs_size { 50 };
144 string left =
key.substr(0, flangs_size);
145 string right =
key.substr(
key.length() - flangs_size - 1);
173 catch(
const std::system_error& e) {
174 LOG_POST(
Error <<
"Failed to start the cache heartbeat thread: " << e.what());
189 catch(
const std::system_error& e) {
190 LOG_POST(
Error <<
"Failed to join the cache heartbeat thread: " << e.what());
198 this_thread::sleep_for(chrono::seconds(2));
210 string cache_svc = reg.
GetString(cache,
"service", service);
211 string cache_name = reg.
GetString(cache,
"cache", db);
212 LOG_POST(
Info <<
"x_InitICache, service: " << cache_svc <<
", cache: " << cache_name);
227 underlying_type_t< ECacheState > st {
state };
virtual CNetICacheClient x_InitBlobCache()=0
Creates the BLOB NetCache instance.
ECacheState SetState(ECacheState desired_state)
Changes the state of the cache object.
void x_WriteState(ECacheState state, unsigned int ttl=300)
Writes a new state to the sync object.
const std::string GetCompoundKey() const
Returns the compound NetCache key of the BLOB.
virtual ~CDataCrawlerCache()
Destructor.
void x_StopHeartbeat()
Stops the heartbeat (thread to keep the sybc object alive)
ECacheState
Cache object states.
@ eState_Created
The remote file is not accessible.
@ eState_NotAccessible
The remote file is being processed.
@ eState_InProgress
No cache data.
ECacheType
Types of cache objects.
@ eCache_Sync
BLOB object.
void x_StartHeartbeat()
Starts the heartbeat (thread to keep the sybc object alive)
std::string m_BlobKey
The NetCache key of the BLOB object.
size_t GetReadSize() const
Returns size of existing BLOB data.
CNetICacheClient m_SyncCache
Sync objects NetCache instance.
void Remove()
Removes the cache entry.
void x_Initialize()
Initializes the cache instances.
bool m_isImmutableKey
do not try to shorten or otherwise modify the root cache key
void x_Heartbeat()
The heartbeat thread function.
CNetICacheClient x_InitICache(const std::string &cache, const std::string &service, const std::string &db)
Creates a NetCache instance.
virtual CNetICacheClient x_InitSyncCache()=0
Creates the sync NetCache instance.
std::unique_ptr< CNcbiOstream > GetWriteStream()
Returns stream interface to write BLOB data.
std::unique_ptr< std::thread > m_Heartbeat
The heartbeat thread.
std::atomic_bool m_StopHeartbeat
Boolean flag to stop the heartbeat thread.
std::mutex m_SyncCacheMutex
Mutex, controlling the access to the sync cache.
CNetICacheClient m_BlobCache
Blobs NetCache instance.
std::unique_ptr< CNcbiIstream > GetReadStream()
Returns stream interface to read BLOB data.
ECacheState x_ReadState() const
Reads the state of the sync object.
ECacheState GetState() const
Gets the state of the cache object.
virtual std::string x_GetCacheKey()=0
Generates the cache key.
std::string m_SyncKey
The NetCache key of the sync object.
static CNcbiApplication * Instance(void)
Singleton method.
Client to NetCache server (implements ICache interface)
const string & GetServiceName() const
static string Create(const string &service_name, const string &cache_name, const string &key, const string &subkey, const TVersion &version=null)
Note about the "buf_size" parameter for streams in this API.
@ fOwnReader
Own the underlying reader.
@ fOwnWriter
Own the underlying writer.
Writer-based output stream.
@ fBestReliability
Usually, it's not a problem if something fails to get cached sometimes.
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
void Error(CExceptionArgs_Base &args)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
void Info(CExceptionArgs_Base &args)
IReader * GetReadStream(const string &key, int version, const string &subkey, size_t *blob_size_ptr, const CNamedParameterList *optional=NULL)
Read a lengthy blob via the IReader interface.
virtual string GetCacheName(void) const
virtual void Store(const string &key, int version, const string &subkey, const void *data, size_t size, unsigned int time_to_live=0, const string &owner=kEmptyStr)
Add or replace BLOB.
virtual void Remove(const string &key, int version, const string &subkey)
Remove specific cache entry.
virtual bool Read(const string &key, int version, const string &subkey, void *buf, size_t buf_size)
bool HasBlob(const string &key, const string &subkey, const CNamedParameterList *optional=NULL)
virtual IWriter * GetWriteStream(const string &key, int version, const string &subkey, unsigned int time_to_live=0, const string &owner=kEmptyStr)
Return sequential stream interface to write BLOB data.
virtual void SetFlags(TFlags flags)
Pass flags to the underlying storage.
virtual size_t GetSize(const string &key, int version, const string &subkey)
Check if BLOB exists, return BLOB size.
virtual string GetString(const string §ion, const string &name, const string &default_value, TFlags flags=0) const
Get the parameter string value.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
CMD5 - class for computing Message Digest version 5 checksums.
const struct ncbi::grid::netcache::search::fields::KEY key
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Process information in the NCBI Registry, including working with configuration files.
Reader-writer based streams.