示例#1
0
 @Override
 public synchronized void close() throws IOException {
   super.close();
   DataOutputStream out = fs.create(new Path(dir, BLOOM_FILE_NAME), true);
   bloomFilter.write(out);
   out.flush();
   out.close();
 }
示例#2
0
 @Override
 public synchronized void append(WritableComparable key, Writable val) throws IOException {
   super.append(key, val);
   buf.reset();
   key.write(buf);
   bloomKey.set(byteArrayForBloomKey(buf), 1.0);
   bloomFilter.add(bloomKey);
 }
示例#3
0
 /**
  * Checks if this MapFile has the indicated key. The membership test is performed using a Bloom
  * filter, so the result has always non-zero probability of false positives.
  *
  * @param key key to check
  * @return false iff key doesn't exist, true if key probably exists.
  * @throws IOException
  */
 public boolean probablyHasKey(WritableComparable key) throws IOException {
   if (bloomFilter == null) {
     return true;
   }
   buf.reset();
   key.write(buf);
   bloomKey.set(byteArrayForBloomKey(buf), 1.0);
   return bloomFilter.membershipTest(bloomKey);
 }
示例#4
0
 private void initBloomFilter(Path dirName, Configuration conf) {
   try {
     FileSystem fs = dirName.getFileSystem(conf);
     DataInputStream in = fs.open(new Path(dirName, BLOOM_FILE_NAME));
     bloomFilter = new DynamicBloomFilter();
     bloomFilter.readFields(in);
     in.close();
   } catch (IOException ioe) {
     LOG.warn("Can't open BloomFilter: " + ioe + " - fallback to MapFile.");
     bloomFilter = null;
   }
 }