MediaWiki  REL1_24
BloomCache Class Reference

Persistent bloom filter used to avoid expensive lookups. More...

Inheritance diagram for BloomCache:
Collaboration diagram for BloomCache:

List of all members.

Public Member Functions

 __construct (array $config)
 Create a new bloom cache instance from configuration.
 add ($key, $members)
 Add a member to the bloom filter at $key.
 check ($domain, $type, $member)
 Check if a member is set in the bloom filter.
 delete ($key)
 Destroy a bloom filter at $key.
 getScopedLock ($virtualKey)
 Get an exclusive lock on a filter for updates.
 getStatus ($virtualKey)
 Get the status map of the virtual bloom filter at $key.
 init ($key, $size=1000000, $precision=.001)
 Create a new bloom filter at $key (if one does not exist yet)
 insert ($domain, $type, $members)
 Inform the bloom filter of a new member in order to keep it up to date.
 isHit ($key, $member)
 Check if a member is set in the bloom filter.
 setStatus ($virtualKey, array $values)
 Set the status map of the virtual bloom filter at $key.

Static Public Member Functions

static get ($id)

Protected Member Functions

 doAdd ($key, array $members)
 doDelete ($key)
 doGetStatus ($key)
 doInit ($key, $size, $precision)
 doIsHit ($key, $member)
 doSetStatus ($virtualKey, array $values)

Protected Attributes

string $cacheID
 Unique ID for key namespacing *.

Static Protected Attributes

static $instances = array()

Detailed Description

Persistent bloom filter used to avoid expensive lookups.

Since:
1.24

Definition at line 27 of file BloomCache.php.


Constructor & Destructor Documentation

Create a new bloom cache instance from configuration.

This should only be called from within BloomCache.

Parameters:
array$configParameters include:
  • cacheID : Prefix to all bloom filter names that is unique to this cache. It should only consist of alphanumberic, '-', and '_' characters. This ID is what avoids collisions if multiple logical caches use the same storage system, so this should be set carefully.

Reimplemented in EmptyBloomCache, and BloomCacheRedis.

Definition at line 63 of file BloomCache.php.


Member Function Documentation

BloomCache::add ( key,
members 
) [final]

Add a member to the bloom filter at $key.

Parameters:
string$key
string | array$members
Returns:
bool Success

Definition at line 174 of file BloomCache.php.

Referenced by BloomFilterTitleHasLogs\merge().

BloomCache::check ( domain,
type,
member 
) [final]

Check if a member is set in the bloom filter.

A member being set means that it *might* have been added. A member not being set means it *could not* have been added.

This abstracts over isHit() to deal with filter updates and readiness. A class must exist with the name BloomFilter<type> and a static public mergeAndCheck() method. The later takes the following arguments: (BloomCache $bcache, $domain, $virtualKey, array $status) The method should return a bool indicating whether to use the filter.

The 'shared' bloom key must be used for any updates and will be used for the membership check if the method returns true. Since the key is shared, the method should never use delete(). The filter cannot be used in cases where membership in the filter needs to be taken away. In such cases, code *cannot* use this method - instead, it can directly use the other BloomCache methods to manage custom filters with their own keys (e.g. not 'shared').

Parameters:
string$domain
string$type
string$member
Returns:
bool True if set, false if not (also returns true on error)

Definition at line 94 of file BloomCache.php.

BloomCache::delete ( key) [final]

Destroy a bloom filter at $key.

Parameters:
string$key
Returns:
bool Success

Definition at line 205 of file BloomCache.php.

BloomCache::doAdd ( key,
array members 
) [abstract, protected]
Parameters:
string$key
array$members
Returns:
bool Success

Reimplemented in EmptyBloomCache, and BloomCacheRedis.

BloomCache::doDelete ( key) [abstract, protected]
Parameters:
string$key
Returns:
bool Success

Reimplemented in EmptyBloomCache, and BloomCacheRedis.

BloomCache::doGetStatus ( key) [abstract, protected]
Parameters:
string$key
Returns:
array|bool

Reimplemented in EmptyBloomCache, and BloomCacheRedis.

BloomCache::doInit ( key,
size,
precision 
) [abstract, protected]
Parameters:
string$key
integer$sizeBit length
float$precision
Returns:
bool Success

Reimplemented in EmptyBloomCache, and BloomCacheRedis.

BloomCache::doIsHit ( key,
member 
) [abstract, protected]
Parameters:
string$key
string$member
Returns:
bool|null

Reimplemented in EmptyBloomCache, and BloomCacheRedis.

BloomCache::doSetStatus ( virtualKey,
array values 
) [abstract, protected]
Parameters:
string$virtualKey
array$values
Returns:
bool Success

Reimplemented in EmptyBloomCache, and BloomCacheRedis.

static BloomCache::get ( id) [static, final]
BloomCache::getScopedLock ( virtualKey)

Get an exclusive lock on a filter for updates.

Parameters:
string$virtualKey
Returns:
ScopedCallback|ScopedLock|null Returns null if acquisition failed

Reimplemented in BloomCacheRedis.

Definition at line 248 of file BloomCache.php.

Referenced by BloomFilterTitleHasLogs\mergeAndCheck().

BloomCache::getStatus ( virtualKey) [final]

Get the status map of the virtual bloom filter at $key.

The map includes:

  • lastID : the highest ID of the items merged in
  • asOfTime : UNIX timestamp that the filter is up-to-date as of
  • epoch : UNIX timestamp that filter started being populated Unset fields will have a null value.
Parameters:
string$virtualKey
Returns:
array|bool False on failure

Definition at line 236 of file BloomCache.php.

BloomCache::init ( key,
size = 1000000,
precision = .001 
) [final]

Create a new bloom filter at $key (if one does not exist yet)

Parameters:
string$key
integer$sizeBit length [default: 1000000]
float$precision[default: .001]
Returns:
bool Success

Definition at line 161 of file BloomCache.php.

BloomCache::insert ( domain,
type,
members 
) [final]

Inform the bloom filter of a new member in order to keep it up to date.

Parameters:
string$domain
string$type
string | array$members
Returns:
bool Success

Definition at line 132 of file BloomCache.php.

BloomCache::isHit ( key,
member 
) [final]

Check if a member is set in the bloom filter.

A member being set means that it *might* have been added. A member not being set means it *could not* have been added.

If this returns true, then the caller usually should do the expensive check (whatever that may be). It can be avoided otherwise.

Parameters:
string$key
string$member
Returns:
bool|null True if set, false if not, null on error

Definition at line 193 of file BloomCache.php.

BloomCache::setStatus ( virtualKey,
array values 
) [final]

Set the status map of the virtual bloom filter at $key.

Parameters:
string$virtualKey
array$valuesMap including some of (lastID, asOfTime, epoch)
Returns:
bool Success

Definition at line 218 of file BloomCache.php.

Referenced by BloomFilterTitleHasLogs\merge().


Member Data Documentation

string BloomCache::$cacheID [protected]

Unique ID for key namespacing *.

Definition at line 28 of file BloomCache.php.

BloomCache::$instances = array() [static, protected]

Definition at line 31 of file BloomCache.php.


The documentation for this class was generated from the following file: