Files

109 lines
2.5 KiB
C
Raw Permalink Normal View History

2016-01-30 20:11:15 +01:00
// Matt Wells, copyright Nov 2002
2016-03-08 22:14:30 +01:00
#ifndef GB_DOLEDB_H
#define GB_DOLEDB_H
2016-01-30 20:11:15 +01:00
#include "Rdb.h"
2016-11-11 15:45:39 +01:00
#include "types.h"
2016-01-30 20:11:15 +01:00
#include "hash.h"
2016-06-28 11:01:47 +02:00
#include "Sanity.h"
2016-01-30 20:11:15 +01:00
2016-11-11 15:45:39 +01:00
class Msg5;
class RdbList;
2016-01-30 20:11:15 +01:00
void gotDoledbListWrapper2 ( void *state , RdbList *list , Msg5 *msg5 ) ;
// . store urls that can be spidered right NOW in doledb
// . SpiderLoop.cpp doles out urls from its local spiderdb into
// the doledb rdb of remote hosts (and itself as well sometimes!)
// . then each host calls SpiderLoop::spiderDoledUrls() to spider the
// urls doled to their group (shard) in doledb
class Doledb {
public:
2016-01-30 20:11:15 +01:00
void reset();
bool init ( );
// . see "overview of spidercache" below for key definition
// . these keys when hashed are clogging up the hash table
// so i am making the 7 reserved bits part of the urlhash48...
static key96_t makeKey(int32_t priority, uint32_t spiderTime, int64_t urlHash48, bool isDelete) {
2016-01-30 20:11:15 +01:00
// sanity checks
2016-06-20 19:29:10 +02:00
if ( priority & 0xffffff00 ) { gbshutdownAbort(true); }
if ( urlHash48 & 0xffff000000000000LL ) { gbshutdownAbort(true); }
key96_t k;
2016-01-30 20:11:15 +01:00
k.n1 = (255 - priority);
k.n1 <<= 24;
k.n1 |= (spiderTime >>8);
k.n0 = spiderTime & 0xff;
k.n0 <<= 48;
k.n0 |= urlHash48;
// 7 bits reserved
k.n0 <<= 7;
// still reserved but when adding to m_doleReqTable it needs
// to be more random!! otherwise the hash table is way slow!
k.n0 |= (urlHash48 & 0x7f);
// 1 bit for negative bit
k.n0 <<= 1;
// we are positive or not? setting this means we are positive
if ( ! isDelete ) k.n0 |= 0x01;
return k;
2016-05-19 18:37:26 +02:00
}
2016-01-30 20:11:15 +01:00
static key96_t makeFirstKey2 ( int32_t priority ) {
key96_t k;
k.setMin();
2016-01-30 20:11:15 +01:00
// set priority
k.n1 = (255 - priority);
k.n1 <<= 24;
return k;
2016-05-19 18:37:26 +02:00
}
2016-01-30 20:11:15 +01:00
static key96_t makeLastKey2 ( int32_t priority ) {
key96_t k;
k.setMax();
2016-01-30 20:11:15 +01:00
// set priority
k.n1 = (255 - priority);
k.n1 <<= 24;
k.n1 |= 0x00ffffff;
return k;
2016-05-19 18:37:26 +02:00
}
2016-01-30 20:11:15 +01:00
2017-08-03 14:07:23 +02:00
static int32_t getPriority(const key96_t *k) {
return 255 - ((k->n1 >> 24) & 0xff);
}
2017-08-03 14:07:23 +02:00
static int32_t getSpiderTime(const key96_t *k) {
2016-01-30 20:11:15 +01:00
uint32_t spiderTime = (k->n1) & 0xffffff;
spiderTime <<= 8;
// upper 8 bits of k.n0 are lower 8 bits of spiderTime
spiderTime |= (uint32_t)((k->n0) >> (64-8));
return (int32_t)spiderTime;
2016-05-19 18:37:26 +02:00
}
2017-08-03 14:07:23 +02:00
static int32_t getIsDel(const key96_t *k) {
2016-01-30 20:11:15 +01:00
if ( (k->n0 & 0x01) ) return 0;
return 1;
}
2016-01-30 20:11:15 +01:00
2017-08-03 14:07:23 +02:00
static int64_t getUrlHash48(const key96_t *k) {
return (k->n0>>8)&0x0000ffffffffffffLL;
}
2016-01-30 20:11:15 +01:00
2016-05-19 18:37:26 +02:00
Rdb *getRdb() { return &m_rdb;}
2016-01-30 20:11:15 +01:00
private:
2016-01-30 20:11:15 +01:00
Rdb m_rdb;
};
extern class Doledb g_doledb;
void nukeDoledb ( collnum_t collnum ) ;
void nukeAllDoledbs();
2016-01-30 20:11:15 +01:00
2016-03-08 22:14:30 +01:00
#endif // GB_DOLEDB_H