com.sun.labs.minion.indexer.partition
Class DelMap

java.lang.Object
  extended by com.sun.labs.minion.indexer.partition.DelMap
All Implemented Interfaces:
java.lang.Cloneable

public class DelMap
extends java.lang.Object
implements java.lang.Cloneable

A class that holds the two components of a deletion map: the number of documents deleted and the bitmap of the deleted documents.


Field Summary
protected  java.io.File delFile
          The file that contains the deletion map we're managing.
protected  Buffer delMap
          The bitmap of deleted documents.
protected  boolean dirty
          Whether the bitmap has been modified since it was read.
protected  FileLock lock
          A lock for the file.
protected static java.lang.String logTag
          The log tag.
protected  int nDeleted
          The number of deleted documents.
 
Constructor Summary
DelMap()
          Creates an empty deletion bitmap.
DelMap(java.io.File delFile, FileLock lock)
          Instantiates a DelMap from the given file, which is locked with the given lock.
 
Method Summary
 void clear()
          Clears out the map.
 java.lang.Object clone()
          Clones this map.
 boolean delete(int id)
          Sets the bit indicating tha the given ID has been deleted.
 ReadableBuffer getDelMap()
          Gets the current deletion map.
 int getNDeleted()
          Gets the number of deleted documents.
 boolean isDeleted(int id)
          Tells us whether a document has been deleted.
static void main(java.lang.String[] args)
          A main program that prints out a deletion map.
protected  void read()
          Reads the deletion bitmap from the file, and computes the number of deleted documents.
protected  Buffer readBuffer()
          Reads the deletion bitmap from the file, locking if necessary.
 void setPartition(Partition part)
           
protected  void sync()
          Synchronizes the map in memory with the map on disk.
protected  ReadableBuffer syncGetMap()
          A helper that atomically syncs the deletion map and returns the buffer.
 java.lang.String toString()
           
 void write()
          Writes this map to a file.
 void write(java.io.File delFile)
          Writes this map to a file.
static void write(java.io.File f, WriteableBuffer m)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

delFile

protected java.io.File delFile
The file that contains the deletion map we're managing.


lock

protected FileLock lock
A lock for the file.


nDeleted

protected int nDeleted
The number of deleted documents.


delMap

protected Buffer delMap
The bitmap of deleted documents.


dirty

protected boolean dirty
Whether the bitmap has been modified since it was read.


logTag

protected static java.lang.String logTag
The log tag.

Constructor Detail

DelMap

public DelMap()
Creates an empty deletion bitmap.


DelMap

public DelMap(java.io.File delFile,
              FileLock lock)
Instantiates a DelMap from the given file, which is locked with the given lock.

Parameters:
delFile - The file that the deletion map is read from.
lock - The lock for that file.
Method Detail

setPartition

public void setPartition(Partition part)

readBuffer

protected Buffer readBuffer()
Reads the deletion bitmap from the file, locking if necessary. This merely returns the buffer, it does not set the deletion bitmap!

Returns:
the buffer containing the deletion bitmap.

read

protected void read()
Reads the deletion bitmap from the file, and computes the number of deleted documents.


write

public static void write(java.io.File f,
                         WriteableBuffer m)
                  throws java.io.IOException
Throws:
java.io.IOException

write

public void write()
Writes this map to a file.


write

public void write(java.io.File delFile)
Writes this map to a file.

Parameters:
delFile - the file to which we'll write the deletion map

sync

protected void sync()
Synchronizes the map in memory with the map on disk.


syncGetMap

protected ReadableBuffer syncGetMap()
A helper that atomically syncs the deletion map and returns the buffer.

Returns:
the synchronized deletion map

delete

public boolean delete(int id)
Sets the bit indicating tha the given ID has been deleted.

Parameters:
id - the ID of the document to delete
Returns:
true if the document was deleted successfully, false otherwise. Note that we will return false if this ID has already been deleted in this map. That is, this method will only return true the first time that a document is deleted.

isDeleted

public boolean isDeleted(int id)
Tells us whether a document has been deleted.

Parameters:
id - the ID of the document that we want to check
Returns:
true if the document has been deleted, false otherwise.

clear

public void clear()
Clears out the map.


clone

public java.lang.Object clone()
Clones this map.

Overrides:
clone in class java.lang.Object

getNDeleted

public int getNDeleted()
Gets the number of deleted documents.

Returns:
the number of deleted documents

getDelMap

public ReadableBuffer getDelMap()
Gets the current deletion map. A clone of the map is returned, so that the caller can't affect our representation of deleted documents.

Returns:
a copy of the current deletion map.
See Also:
syncGetMap()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
A main program that prints out a deletion map.

Throws:
java.lang.Exception