|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object rice.persistence.PersistentStorage
public class PersistentStorage
This class is an implementation of Storage which provides persistent storage to disk. This class also guarentees that the data will be consistent, even after a crash. This class also provides these services is a non-blocking fashion by launching a seperate thread which is tasked with actaully writing the data to disk. This class was initially designed to support only Ids whose toString() method returns a String of constant length. It has been exteneded to support variable-length toString()s, but we have the caveat that not toString() can be a substring of another toString() - this will cause undefined behavior. Additionally, the toString() method on the key Ids *CANNOT* have the period ('.') or exclamation point ('!') characters in them - these are used for internal purposes. The serialized objects are stored on-disk in a GZIPed XML format, which provides extensibility with reasonable storage and processing costs. Additionally, any metadata, if provided, is also stored in the on-disk file. The format of the file is [Key, Object, Version, Gzipped XML] [Metadata, Gzipped XML] [persistence magic number, long] [persistence version, long] [persistence revision, long] [metadata length, long] The persistence package is set up to automatically upgrade older versions of the on-disk format as new data is written under the key. Persistence also supports the metadata interface specified in the Catalog interface. All metadata is guaranteeded to be stored in memory, so fetching the metadata of a given key is an efficient operation.
Field Summary | |
---|---|
static java.lang.String |
BACKUP_DIRECTORY
Static variables which define the location of the storage root |
static java.lang.String |
LOST_AND_FOUND_DIRECTORY
|
static int |
MAX_DIRECTORIES
The maximum number of subdirectories in a directory before splitting |
static int |
MAX_FILES
The splitting factor, or the number of files in one directory |
static java.lang.String |
METADATA_FILENAME
|
static int |
METADATA_SYNC_TIME
The amount of time before re-writing the metadata file |
static long |
PERSISTENCE_MAGIC_NUMBER
Static variables defining the layout of the on-disk storage |
static long |
PERSISTENCE_REVISION_2_0
|
static long |
PERSISTENCE_REVISION_2_1
|
static long |
PERSISTENCE_VERSION_2
|
static java.lang.String |
ZERO_LENGTH_NAME
Special placeholder for the file whose name should be zero-length |
Constructor Summary | |
---|---|
PersistentStorage(IdFactory factory,
java.lang.String rootDir,
long size,
Environment env)
Builds a PersistentStorage given a root directory in which to persist the data. |
|
PersistentStorage(IdFactory factory,
java.lang.String name,
java.lang.String rootDir,
long size,
boolean index,
Environment env)
Builds a PersistentStorage given and an instance name and a root directoy in which to persist the data. |
|
PersistentStorage(IdFactory factory,
java.lang.String name,
java.lang.String rootDir,
long size,
Environment env)
Builds a PersistentStorage given and an instance name and a root directoy in which to persist the data. |
Method Summary | |
---|---|
boolean |
exists(Id id)
Returns whether or not an object is present in the location id . |
void |
flush(Continuation c)
Method which is used to erase all data stored in the Catalog. |
java.io.Serializable |
getMetadata(Id id)
Returns the metadata associated with the provided object, or null if no metadata exists. |
java.lang.String |
getName()
Gets the name of this instance |
void |
getObject(Id id,
Continuation c)
Returns the object identified by the given id. |
protected IdRange |
getRangeForDirectory(java.io.File dir)
Utility function which returns the range of keys which a directory corresponds to. |
java.lang.String |
getRoot()
gets the root directory that the persistence Manager uses |
int |
getSize()
Returns the number of Ids currently stored in the catalog |
long |
getStorageSize()
gets the amount of storage that the persistence Manager uses |
long |
getTotalSize()
Returns the total size of the stored data in bytes.The result is returned via the receiveResult method on the provided Continuation with an Integer representing the size. |
void |
rename(Id oldId,
Id newId,
Continuation c)
Renames the given object to the new id. |
IdSet |
scan()
Return the objects identified by the given range of ids. |
IdSet |
scan(IdRange range)
Return the objects identified by the given range of ids. |
java.util.SortedMap |
scanMetadata()
Returns a map which contains keys mapping ids to the associated metadata. |
java.util.SortedMap |
scanMetadata(IdRange range)
Returns a map which contains keys mapping ids to the associated metadata. |
java.util.SortedMap |
scanMetadataValuesHead(java.lang.Object value)
Returns the submapping of ids which have metadata less than the provided value. |
java.util.SortedMap |
scanMetadataValuesNull()
Returns the submapping of ids which have metadata null |
void |
setMetadata(Id id,
java.io.Serializable metadata,
Continuation c)
Updates the metadata stored under the given key to be the provided value. |
boolean |
setRoot(java.lang.String dir)
Sets the root directory that the persistence Manager uses |
boolean |
setStorageSize(long size)
Sets the amount of storage that the persistence Manager uses |
void |
setTimer(Timer timer)
Method which allows the persistence root to schedle an event which will tell it to sync the metadata cached. |
void |
store(Id id,
java.io.Serializable metadata,
java.io.Serializable obj,
Continuation c)
Makes the object persistent to disk and stored permanantly If the object is already persistent, this method will simply update the object's serialized image. |
void |
unstore(Id id,
Continuation c)
Request to remove the object from the list of persistend objects. |
protected void |
writeDirty()
Function which writes out all of the dirty metadata files and marks them as clean. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long PERSISTENCE_MAGIC_NUMBER
public static final long PERSISTENCE_VERSION_2
public static final long PERSISTENCE_REVISION_2_0
public static final long PERSISTENCE_REVISION_2_1
public static final java.lang.String BACKUP_DIRECTORY
public static final java.lang.String LOST_AND_FOUND_DIRECTORY
public static final java.lang.String METADATA_FILENAME
public static final int MAX_FILES
public static final int MAX_DIRECTORIES
public static final int METADATA_SYNC_TIME
public static final java.lang.String ZERO_LENGTH_NAME
Constructor Detail |
---|
public PersistentStorage(IdFactory factory, java.lang.String rootDir, long size, Environment env) throws java.io.IOException
factory
- The factory to use for creating Ids.rootDir
- The root directory of the persisted disk.size
- the size of the storage in bytes, or -1 for unlimited
java.io.IOException
public PersistentStorage(IdFactory factory, java.lang.String name, java.lang.String rootDir, long size, Environment env) throws java.io.IOException
factory
- The factory to use for creating Ids.name
- the name of this instancerootDir
- The root directory of the persisted disk.size
- the size of the storage in bytes, or -1 for unlimited
java.io.IOException
public PersistentStorage(IdFactory factory, java.lang.String name, java.lang.String rootDir, long size, boolean index, Environment env) throws java.io.IOException
factory
- The factory to use for creating Ids.name
- the name of this instancerootDir
- The root directory of the persisted disk.size
- the size of the storage in bytes, or -1 for unlimitedindex
- Whether or not to index the objects
java.io.IOException
Method Detail |
---|
public void setTimer(Timer timer)
timer
- The timer to use to schedule the eventspublic void rename(Id oldId, Id newId, Continuation c)
rename
in interface Catalog
oldId
- The id of the object in question.newId
- The new id of the object in question.c
- The command to run once the operation is completepublic void store(Id id, java.io.Serializable metadata, java.io.Serializable obj, Continuation c)
store
in interface Storage
obj
- The object to be made persistent.id
- The object's id.metadata
- The object's metadatac
- The command to run once the operation is completepublic void unstore(Id id, Continuation c)
false
is returned.
This method also guarantees that the data on disk will remain consistent,
even after a crash by performing the delete atomically.
This method completes by calling recieveResult() of the provided continuation
with the success or failure of the operation.
unstore
in interface Storage
id
- The object's persistence idc
- The command to run once the operation is completepublic boolean exists(Id id)
id
.
exists
in interface Catalog
id
- The id of the object in question.
public java.io.Serializable getMetadata(Id id)
getMetadata
in interface Catalog
id
- The id for which the metadata is needed
public void setMetadata(Id id, java.io.Serializable metadata, Continuation c)
setMetadata
in interface Catalog
id
- The id for the metadatametadata
- The metadata to storec
- The command to run once the operation is completepublic void getObject(Id id, Continuation c)
getObject
in interface Catalog
id
- The id of the object in question.c
- The command to run once the operation is completepublic IdSet scan(IdRange range)
scan
in interface Catalog
range
- The range to query
public IdSet scan()
scan
in interface Catalog
public java.util.SortedMap scanMetadata(IdRange range)
scanMetadata
in interface Catalog
range
- The range to query
public java.util.SortedMap scanMetadata()
scanMetadata
in interface Catalog
public java.util.SortedMap scanMetadataValuesHead(java.lang.Object value)
scanMetadataValuesHead
in interface Catalog
value
- The maximal metadata value
public java.util.SortedMap scanMetadataValuesNull()
scanMetadataValuesNull
in interface Catalog
public long getTotalSize()
getTotalSize
in interface Catalog
c
- The command to run once the operation is complete
public int getSize()
getSize
in interface Catalog
public void flush(Continuation c)
flush
in interface Catalog
c
- The command to run once doneprotected void writeDirty()
protected IdRange getRangeForDirectory(java.io.File dir)
dir
- The directorypublic boolean setRoot(java.lang.String dir)
dir
- the String representing the directory to use
public java.lang.String getRoot()
public long getStorageSize()
public boolean setStorageSize(long size)
size
- the amount of storage available to use in bytes
public java.lang.String getName()
|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |