|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.neo4j.kernel.impl.nioneo.store.IdGeneratorImpl
public class IdGeneratorImpl
This class generates unique ids for a resource type. For example, nodes in a nodes space are connected to each other via relationships. On nodes and relationship one can add properties. We have three different resource types here (nodes, relationships and properties) where each resource needs a unique id to be able to differ resources of the same type from each other. Creating three id generators (one for each resource type ) will do the trick.
IdGenerator makes use of so called "defragged" ids. A
defragged id is an id that has been in use one or many times but the resource
that was using it doesn't exist anymore. This makes it possible to reuse the
id and that in turn makes it possible to write a resource store with fixed
records and size (you can calculate the position of a record by knowing the
id without using indexes or a translation table).
The id returned from nextId() may not be the lowest
available id but will be one of the defragged ids if such exist or the next
new free id that has never been used.
The freeId(long) will not check if the id passed in to it really is free.
Passing a non free id will corrupt the id generator and nextId()
method will eventually return that id.
The #close() method must always be invoked when done using an
generator (for this time). Failure to do will render the generator as
"sticky" and unusable next time you try to initialize a generator using the
same file. There can only be one id generator instance per id generator file.
In case of disk/file I/O failure an IOException is thrown.
| Field Summary | |
|---|---|
static long |
INTEGER_MINUS_ONE
|
| Constructor Summary | |
|---|---|
IdGeneratorImpl(String fileName,
int grabSize,
long max,
boolean aggressiveReuse)
Opens the id generator represented by fileName. |
|
| Method Summary | |
|---|---|
void |
clearFreeIds()
|
void |
close(boolean shutdown)
Closes the id generator flushing defragged ids in memory to file. |
static void |
createGenerator(String fileName)
Creates a new id generator. |
void |
delete()
|
void |
dumpFreeIds()
Utility method that will dump all defragged id's and the "high id" to console. |
void |
freeId(long id)
Frees the id making it a defragged id that will be
returned by next id before any new id (that hasn't been used yet) is
returned. |
long |
getDefragCount()
|
String |
getFileName()
Returns the file associated with this id generator. |
long |
getHighId()
Returns the next "high" id that will be returned if no defragged ids exist. |
long |
getNumberOfIdsInUse()
|
long |
nextId()
Returns the next "free" id. |
IdRange |
nextIdBatch(int size)
|
void |
setHighId(long id)
Sets the next free "high" id. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long INTEGER_MINUS_ONE
| Constructor Detail |
|---|
public IdGeneratorImpl(String fileName,
int grabSize,
long max,
boolean aggressiveReuse)
fileName. The
grabSize means how many defragged ids we should keep in
memory and is also the size (x4) of the two buffers used for reading and
writing to the id generator file. The highest returned id will be read
from file and if grabSize number of ids exist they will be
read into memory (if less exist all defragged ids will be in memory).
If this id generator hasn't been closed properly since the previous
session (sticky) an IOException will be thrown. When this
happens one has to rebuild the id generator from the (node/rel/prop)
store file.
fileName - The file name (and path if needed) for the id generator to be
openedgrabSize - The number of defragged ids to keep in memorymax - is the highest possible id to be returned by this id generator from
nextId().aggressiveReuse - will reuse ids during the same session, not requiring
a restart to be able reuse ids freed with freeId(long).
UnderlyingStorageException - If no such file exist or if the id generator is sticky| Method Detail |
|---|
public long nextId()
UnderlyingStorageException will be thrown.
nextId in interface IdGeneratorUnderlyingStorageException - If the capacity is exceeded
IllegalStateException - if this id generator has been closedpublic IdRange nextIdBatch(int size)
nextIdBatch in interface IdGeneratorpublic void setHighId(long id)
id must not be higher than max.
setHighId in interface IdGeneratorid - The next free idpublic long getHighId()
getHighId in interface IdGeneratorpublic void freeId(long id)
id making it a defragged id that will be
returned by next id before any new id (that hasn't been used yet) is
returned.
This method will throw an IOException if id is negative or
if id is greater than the highest returned id. However as stated in the
class documentation above the id isn't validated to see if it really is
free.
freeId in interface IdGeneratorid - The id to be made available again
IOException - If id is negative or greater than the highest returned idpublic void close(boolean shutdown)
An invoke to the nextId or freeId after
this method has been invoked will result in an IOException
since the highest returned id has been set to a negative value.
close in interface IdGeneratorshutdown - true if this is during shutdown of the database, false
if it's an intermediary close, f.ex after rebuilding id generators at startup.
IOException - If unable to close this id generatorpublic String getFileName()
public static void createGenerator(String fileName)
fileName - The name of the id generator
IOException - If unable to create the id generatorpublic void dumpFreeIds()
IOException - If problem dumping free idspublic long getNumberOfIdsInUse()
getNumberOfIdsInUse in interface IdGeneratorpublic long getDefragCount()
getDefragCount in interface IdGeneratorpublic void clearFreeIds()
public void delete()
delete in interface IdGenerator
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||