Baqend / Orestes-Bloomfilter

Library of different Bloom filters in Java with optional Redis-backing, counting and many hashing options.
Other
843 stars 245 forks source link

Remote Redis filters with shared pools change to 'localhost' if they already exist #28

Closed ChrisCurtin closed 8 years ago

ChrisCurtin commented 8 years ago

Hi,

I commented on this in a closed thread, so moving it here as something new.

Basically, if the filter exists already, the host name changes to localhost when you try to access it.

Steps:

flushall in Redis run the script below, it will run through all cases, including passing the correct hostname on to the third filter created. run the script again. Note that the host is now localhost, and then we can't connect to a remote database. flushall in Redis repeat running the code twice and it will work the first time, but not the second.

public static void main(String[] args) {

BloomFilter bf = new FilterBuilder(1000000, 0.001) .name("temp") .redisBacked(true) .redisHost("vrd01.atlnp1") .redisConnections(10) .buildBloomFilter();

boolean contains = bf.contains("0"); if (contains) System.out.println("Had it"); else System.out.println("Doesn't have it");

BloomFilter bf1 = new FilterBuilder(1000, 0.001) .name("temp2") .redisBacked(true) .redisHost("vrd01.atlnp1") .buildBloomFilter(); contains = bf1.add("0"); if (!contains) System.out.println("1 Had it"); else System.out.println("1 Doesn't have it");

RedisPool pool = bf1.config().pool(); System.out.println(pool.getHost());

BloomFilter bf2 = new FilterBuilder(1000000, 0.001) .name("second") .redisBacked(true) .pool(pool) .buildBloomFilter();

contains = bf2.contains("0"); if (contains) System.out.println("2 Had it"); else System.out.println("2 Doesn't have it"); }

DivineTraube commented 8 years ago

Hi,

I found the problem that caused this: when a BF exists, the configuration is recovered from a persistent entry in Redis that encodes BF metadata. Since Redis connection metadata was not persisted it was reset to its default value "localhost" causing the above problem.

I made a new release 1.1.4 that fixes this by taking the current pool to fill in the config values when updating using a persisted config.