public abstract class DfsObjDatabase extends ObjectDatabase
DfsPackFile
on a storage system.Modifier and Type | Class and Description |
---|---|
static class |
DfsObjDatabase.PackSource
Sources for a pack file.
|
Modifier | Constructor and Description |
---|---|
protected |
DfsObjDatabase(DfsRepository repository,
DfsReaderOptions options)
Initialize an object database for our repository.
|
Modifier and Type | Method and Description |
---|---|
protected void |
clearCache()
Clears the cached list of packs, forcing them to be scanned again.
|
void |
close()
Close any resources held by this database.
|
protected void |
commitPack(Collection<DfsPackDescription> desc,
Collection<DfsPackDescription> replaces)
Commit a pack and index pair that was written to the DFS.
|
protected abstract void |
commitPackImpl(Collection<DfsPackDescription> desc,
Collection<DfsPackDescription> replaces)
Implementation of pack commit.
|
DfsPackFile[] |
getCurrentPacks()
List currently known pack files in the repository, without scanning.
|
DfsPackFile[] |
getPacks()
Scan and list all available pack files in the repository.
|
DfsReaderOptions |
getReaderOptions() |
protected DfsRepository |
getRepository() |
protected abstract List<DfsPackDescription> |
listPacks()
List the available pack files.
|
ObjectInserter |
newInserter()
Create a new
ObjectInserter to insert new objects. |
protected abstract DfsPackDescription |
newPack(DfsObjDatabase.PackSource source)
Generate a new unique name for a pack file.
|
ObjectReader |
newReader()
Create a new
ObjectReader to read existing objects. |
protected abstract ReadableChannel |
openFile(DfsPackDescription desc,
PackExt ext)
Open a pack, pack index, or other related file for reading.
|
protected abstract void |
rollbackPack(Collection<DfsPackDescription> desc)
Try to rollback a pack creation.
|
protected abstract DfsOutputStream |
writeFile(DfsPackDescription desc,
PackExt ext)
Open a pack, pack index, or other related file for writing.
|
create, exists, has, newCachedDatabase, open, open
protected DfsObjDatabase(DfsRepository repository, DfsReaderOptions options)
repository
- repository owning this object database.options
- how readers should access the object database.public DfsReaderOptions getReaderOptions()
public ObjectReader newReader()
ObjectDatabase
ObjectReader
to read existing objects.
The returned reader is not itself thread-safe, but multiple concurrent
reader instances created from the same ObjectDatabase
must be
thread-safe.
newReader
in class ObjectDatabase
public ObjectInserter newInserter()
ObjectDatabase
ObjectInserter
to insert new objects.
The returned inserter is not itself thread-safe, but multiple concurrent
inserter instances created from the same ObjectDatabase
must be
thread-safe.
newInserter
in class ObjectDatabase
public DfsPackFile[] getPacks() throws IOException
IOException
- the pack list cannot be initialized.protected DfsRepository getRepository()
public DfsPackFile[] getCurrentPacks()
protected abstract DfsPackDescription newPack(DfsObjDatabase.PackSource source) throws IOException
source
- where the pack stream is created.IOException
- a new unique pack description cannot be generated.protected void commitPack(Collection<DfsPackDescription> desc, Collection<DfsPackDescription> replaces) throws IOException
Committing the pack/index pair makes them visible to readers. The JGit DFS code always writes the pack, then the index. This allows a simple commit process to do nothing if readers always look for both files to exist and the DFS performs atomic creation of the file (e.g. stream to a temporary file and rename to target on close).
During pack compaction or GC the new pack file may be replacing other older files. Implementations should remove those older files (if any) as part of the commit of the new file.
This method is a trivial wrapper around
commitPackImpl(Collection, Collection)
that calls the
implementation and fires events.
desc
- description of the new packs.replaces
- if not null, list of packs to remove.IOException
- the packs cannot be committed. On failure a rollback must
also be attempted by the caller.protected abstract void commitPackImpl(Collection<DfsPackDescription> desc, Collection<DfsPackDescription> replaces) throws IOException
desc
- description of the new packs.replaces
- if not null, list of packs to remove.IOException
- the packs cannot be committed.commitPack(Collection, Collection)
protected abstract void rollbackPack(Collection<DfsPackDescription> desc)
JGit DFS always writes the pack first, then the index. If the pack does not yet exist, then neither does the index. A safe DFS implementation would try to remove both files to ensure they are really gone.
A rollback does not support failures, as it only occurs when there is already a failure in progress. A DFS implementor may wish to log warnings/error messages when a rollback fails, but should not send new exceptions up the Java callstack.
desc
- pack to delete.protected abstract List<DfsPackDescription> listPacks() throws IOException
The returned list must support random access and must be mutable by the caller. It is sorted in place using the natural sorting of the returned DfsPackDescription objects.
IOException
- the packs cannot be listed and the object database is not
functional to the caller.protected abstract ReadableChannel openFile(DfsPackDescription desc, PackExt ext) throws FileNotFoundException, IOException
desc
- description of pack related to the data that will be read.
This is an instance previously obtained from
listPacks()
, but not necessarily from the same
DfsObjDatabase instance.ext
- file extension that will be read i.e "pack" or "idx".FileNotFoundException
- the file does not exist.IOException
- the file cannot be opened.protected abstract DfsOutputStream writeFile(DfsPackDescription desc, PackExt ext) throws IOException
desc
- description of pack related to the data that will be written.
This is an instance previously obtained from
newPack(PackSource)
.ext
- file extension that will be written i.e "pack" or "idx".IOException
- the file cannot be opened.protected void clearCache()
public void close()
ObjectDatabase
close
in class ObjectDatabase
Copyright © 2013. All Rights Reserved.