Remove improper assertion use from beagle cache handling code
This commit is contained in:
parent
3dfaa7525b
commit
c030a15780
@ -40,8 +40,17 @@ BeagleQueueCache::BeagleQueueCache(RclConfig *cnf)
|
|||||||
|
|
||||||
int maxmbs = 40;
|
int maxmbs = 40;
|
||||||
cnf->getConfParam("webcachemaxmbs", &maxmbs);
|
cnf->getConfParam("webcachemaxmbs", &maxmbs);
|
||||||
m_cache = new CirCache(ccdir);
|
if ((m_cache = new CirCache(ccdir)) == 0) {
|
||||||
m_cache->create(off_t(maxmbs)*1000*1024, CirCache::CC_CRUNIQUE);
|
LOGERR(("BeagleQueueCache: cant create CirCache object\n"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!m_cache->create(off_t(maxmbs)*1000*1024, CirCache::CC_CRUNIQUE)) {
|
||||||
|
LOGERR(("BeagleQueueCache: cache file creation failed: %s\n",
|
||||||
|
m_cache->getReason().c_str()));
|
||||||
|
delete m_cache;
|
||||||
|
m_cache = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BeagleQueueCache::~BeagleQueueCache()
|
BeagleQueueCache::~BeagleQueueCache()
|
||||||
@ -52,12 +61,18 @@ BeagleQueueCache::~BeagleQueueCache()
|
|||||||
// Read document from cache. Return the metadata as an Rcl::Doc
|
// Read document from cache. Return the metadata as an Rcl::Doc
|
||||||
// @param htt Beagle Hit Type
|
// @param htt Beagle Hit Type
|
||||||
bool BeagleQueueCache::getFromCache(const string& udi, Rcl::Doc &dotdoc,
|
bool BeagleQueueCache::getFromCache(const string& udi, Rcl::Doc &dotdoc,
|
||||||
string& data, string *htt)
|
string& data, string *htt)
|
||||||
{
|
{
|
||||||
string dict;
|
string dict;
|
||||||
|
|
||||||
if (!m_cache->get(udi, dict, data))
|
if (m_cache == 0) {
|
||||||
return false;
|
LOGERR(("BeagleQueueCache::getFromCache: cache is null\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!m_cache->get(udi, dict, data)) {
|
||||||
|
LOGDEB(("BeagleQueueCache::getFromCache: get failed\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ConfSimple cf(dict, 1);
|
ConfSimple cf(dict, 1);
|
||||||
|
|
||||||
|
|||||||
@ -204,8 +204,10 @@ bool BeagleQueueIndexer::indexFromCache(const string& udi)
|
|||||||
string data;
|
string data;
|
||||||
string hittype;
|
string hittype;
|
||||||
|
|
||||||
if (!m_cache || !m_cache->getFromCache(udi, dotdoc, data, &hittype))
|
if (!m_cache || !m_cache->getFromCache(udi, dotdoc, data, &hittype)) {
|
||||||
|
LOGERR(("BeagleQueueIndexer::indexFromCache: cache failed\n"));
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (hittype.empty()) {
|
if (hittype.empty()) {
|
||||||
LOGERR(("BeagleIndexer::index: cc entry has no hit type\n"));
|
LOGERR(("BeagleIndexer::index: cc entry has no hit type\n"));
|
||||||
|
|||||||
@ -19,9 +19,9 @@
|
|||||||
#include "autoconfig.h"
|
#include "autoconfig.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
@ -318,7 +318,10 @@ public:
|
|||||||
|
|
||||||
bool writefirstblock()
|
bool writefirstblock()
|
||||||
{
|
{
|
||||||
assert(m_fd >= 0);
|
if (m_fd < 0) {
|
||||||
|
m_reason << "writefirstblock: not open ";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ostringstream s;
|
ostringstream s;
|
||||||
s <<
|
s <<
|
||||||
@ -344,7 +347,10 @@ public:
|
|||||||
|
|
||||||
bool readfirstblock()
|
bool readfirstblock()
|
||||||
{
|
{
|
||||||
assert(m_fd >= 0);
|
if (m_fd < 0) {
|
||||||
|
m_reason << "readfirstblock: not open ";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
char bf[CIRCACHE_FIRSTBLOCK_SIZE];
|
char bf[CIRCACHE_FIRSTBLOCK_SIZE];
|
||||||
|
|
||||||
@ -387,6 +393,10 @@ public:
|
|||||||
|
|
||||||
bool writeEntryHeader(off_t offset, const EntryHeaderData& d)
|
bool writeEntryHeader(off_t offset, const EntryHeaderData& d)
|
||||||
{
|
{
|
||||||
|
if (m_fd < 0) {
|
||||||
|
m_reason << "writeEntryHeader: not open ";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
char bf[CIRCACHE_HEADER_SIZE];
|
char bf[CIRCACHE_HEADER_SIZE];
|
||||||
memset(bf, 0, CIRCACHE_HEADER_SIZE);
|
memset(bf, 0, CIRCACHE_HEADER_SIZE);
|
||||||
snprintf(bf, CIRCACHE_HEADER_SIZE,
|
snprintf(bf, CIRCACHE_HEADER_SIZE,
|
||||||
@ -405,7 +415,10 @@ public:
|
|||||||
|
|
||||||
CCScanHook::status readEntryHeader(off_t offset, EntryHeaderData& d)
|
CCScanHook::status readEntryHeader(off_t offset, EntryHeaderData& d)
|
||||||
{
|
{
|
||||||
assert(m_fd >= 0);
|
if (m_fd < 0) {
|
||||||
|
m_reason << "readEntryHeader: not open ";
|
||||||
|
return CCScanHook::Error;
|
||||||
|
}
|
||||||
|
|
||||||
if (lseek(m_fd, offset, 0) != offset) {
|
if (lseek(m_fd, offset, 0) != offset) {
|
||||||
m_reason << "readEntryHeader: lseek(" << offset <<
|
m_reason << "readEntryHeader: lseek(" << offset <<
|
||||||
@ -438,7 +451,10 @@ public:
|
|||||||
CCScanHook::status scan(off_t startoffset, CCScanHook *user,
|
CCScanHook::status scan(off_t startoffset, CCScanHook *user,
|
||||||
bool fold = false)
|
bool fold = false)
|
||||||
{
|
{
|
||||||
assert(m_fd >= 0);
|
if (m_fd < 0) {
|
||||||
|
m_reason << "scan: not open ";
|
||||||
|
return CCScanHook::Error;
|
||||||
|
}
|
||||||
|
|
||||||
off_t so0 = startoffset;
|
off_t so0 = startoffset;
|
||||||
bool already_folded = false;
|
bool already_folded = false;
|
||||||
@ -601,7 +617,10 @@ string CirCache::getReason()
|
|||||||
bool CirCache::create(off_t m_maxsize, int flags)
|
bool CirCache::create(off_t m_maxsize, int flags)
|
||||||
{
|
{
|
||||||
LOGDEB(("CirCache::create: [%s] flags 0x%x\n", m_dir.c_str(), flags));
|
LOGDEB(("CirCache::create: [%s] flags 0x%x\n", m_dir.c_str(), flags));
|
||||||
assert(m_d != 0);
|
if (m_d == 0) {
|
||||||
|
LOGERR(("CirCache::create: null data\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat(m_dir.c_str(), &st) < 0) {
|
if (stat(m_dir.c_str(), &st) < 0) {
|
||||||
if (mkdir(m_dir.c_str(), 0777) < 0) {
|
if (mkdir(m_dir.c_str(), 0777) < 0) {
|
||||||
@ -639,7 +658,11 @@ bool CirCache::create(off_t m_maxsize, int flags)
|
|||||||
|
|
||||||
bool CirCache::open(OpMode mode)
|
bool CirCache::open(OpMode mode)
|
||||||
{
|
{
|
||||||
assert(m_d != 0);
|
if (m_d == 0) {
|
||||||
|
LOGERR(("CirCache::open: null data\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_d->m_fd >= 0)
|
if (m_d->m_fd >= 0)
|
||||||
::close(m_d->m_fd);
|
::close(m_d->m_fd);
|
||||||
|
|
||||||
@ -726,9 +749,8 @@ public:
|
|||||||
bool CirCache::get(const string& udi, string& dic, string& data, int instance)
|
bool CirCache::get(const string& udi, string& dic, string& data, int instance)
|
||||||
{
|
{
|
||||||
Chrono chron;
|
Chrono chron;
|
||||||
assert(m_d != 0);
|
|
||||||
if (m_d->m_fd < 0) {
|
if (m_d->m_fd < 0) {
|
||||||
m_d->m_reason << "CirCache::get: not open";
|
m_d->m_reason << "CirCache::get: no data or not open";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -794,9 +816,12 @@ bool CirCache::get(const string& udi, string& dic, string& data, int instance)
|
|||||||
|
|
||||||
bool CirCache::erase(const string& udi)
|
bool CirCache::erase(const string& udi)
|
||||||
{
|
{
|
||||||
assert(m_d != 0);
|
if (m_d == 0) {
|
||||||
|
LOGERR(("CirCache::erase: null data\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (m_d->m_fd < 0) {
|
if (m_d->m_fd < 0) {
|
||||||
m_d->m_reason << "CirCache::erase: not open";
|
m_d->m_reason << "CirCache::erase: no data or not open";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -869,9 +894,12 @@ public:
|
|||||||
bool CirCache::put(const string& udi, const ConfSimple *iconf,
|
bool CirCache::put(const string& udi, const ConfSimple *iconf,
|
||||||
const string& data, unsigned int iflags)
|
const string& data, unsigned int iflags)
|
||||||
{
|
{
|
||||||
assert(m_d != 0);
|
if (m_d == 0) {
|
||||||
|
LOGERR(("CirCache::put: null data\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (m_d->m_fd < 0) {
|
if (m_d->m_fd < 0) {
|
||||||
m_d->m_reason << "CirCache::put: not open";
|
m_d->m_reason << "CirCache::put: no data or not open";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -940,7 +968,10 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf,
|
|||||||
if (m_d->readEntryHeader(m_d->m_nheadoffs, pd) != CCScanHook::Continue){
|
if (m_d->readEntryHeader(m_d->m_nheadoffs, pd) != CCScanHook::Continue){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
assert(int(pd.padsize) == m_d->m_npadsize);
|
if (int(pd.padsize) != m_d->m_npadsize) {
|
||||||
|
m_d->m_reason << "CirCache::put: logic error: bad padsize ";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (pd.dicsize == 0) {
|
if (pd.dicsize == 0) {
|
||||||
// erased entry. Also recover the header space, no need to rewrite
|
// erased entry. Also recover the header space, no need to rewrite
|
||||||
// the header, we're going to write on it.
|
// the header, we're going to write on it.
|
||||||
@ -1033,7 +1064,10 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf,
|
|||||||
|
|
||||||
bool CirCache::rewind(bool& eof)
|
bool CirCache::rewind(bool& eof)
|
||||||
{
|
{
|
||||||
assert(m_d != 0);
|
if (m_d == 0) {
|
||||||
|
LOGERR(("CirCache::rewind: null data\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
eof = false;
|
eof = false;
|
||||||
|
|
||||||
@ -1054,7 +1088,10 @@ bool CirCache::rewind(bool& eof)
|
|||||||
|
|
||||||
bool CirCache::next(bool& eof)
|
bool CirCache::next(bool& eof)
|
||||||
{
|
{
|
||||||
assert(m_d != 0);
|
if (m_d == 0) {
|
||||||
|
LOGERR(("CirCache::next: null data\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
eof = false;
|
eof = false;
|
||||||
|
|
||||||
@ -1087,7 +1124,10 @@ bool CirCache::next(bool& eof)
|
|||||||
|
|
||||||
bool CirCache::getCurrentUdi(string& udi)
|
bool CirCache::getCurrentUdi(string& udi)
|
||||||
{
|
{
|
||||||
assert(m_d != 0);
|
if (m_d == 0) {
|
||||||
|
LOGERR(("CirCache::getCurrentUdi: null data\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_d->readHUdi(m_d->m_itoffs, m_d->m_ithd, udi))
|
if (!m_d->readHUdi(m_d->m_itoffs, m_d->m_ithd, udi))
|
||||||
return false;
|
return false;
|
||||||
@ -1096,7 +1136,10 @@ bool CirCache::getCurrentUdi(string& udi)
|
|||||||
|
|
||||||
bool CirCache::getCurrent(string& udi, string& dic, string& data)
|
bool CirCache::getCurrent(string& udi, string& dic, string& data)
|
||||||
{
|
{
|
||||||
assert(m_d != 0);
|
if (m_d == 0) {
|
||||||
|
LOGERR(("CirCache::getCurrent: null data\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (!m_d->readDicData(m_d->m_itoffs, m_d->m_ithd, dic, &data))
|
if (!m_d->readDicData(m_d->m_itoffs, m_d->m_ithd, dic, &data))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user