|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.faunos.skwish.Segment com.faunos.skwish.sys.BaseSegment com.faunos.skwish.sys.mgr.UnitDir.Seg
public class UnitDir.Seg
A BaseSegment
backed with files in the enclosing
instance's directory.
Field Summary |
---|
Fields inherited from class com.faunos.skwish.sys.BaseSegment |
---|
entryFile, helper, index |
Fields inherited from class com.faunos.skwish.Segment |
---|
validator |
Constructor Summary | |
---|---|
protected |
UnitDir.Seg(FileChannel offsetFile,
FileChannel entryFile)
Access protected constructor. |
Method Summary | |
---|---|
void |
append(BaseSegment segment,
int maxIdGap)
Appends the given segment to this segment. |
void |
appendWithLock(UnitDir.Seg seg)
Appends the given source segment while holding locks on both this, the destination, and source segments. |
boolean |
covers(UnitDir.Seg segment)
Determines whether this instance covers the given segment . |
void |
delete(long id,
int count,
boolean purge)
Checks that appendSourceLock, is not owned by another thread, and also that the instance is not purgeable, and then proceeds with the base delete implementation. |
Lock |
getAppendLock()
Returns the lock held when this instance is either the source or destination of an append. |
Lock |
getAppendSourceLock()
Returns the lock held when this instance is the source of an append. |
void |
getEntry(long id,
ByteBuffer out,
ByteBuffer workBuffer)
Returns the contents of the entry with the specified id. |
long |
getEntrySize(long id,
ByteBuffer workBuffer)
Returns the size of the entry with the specified id. |
String |
getName()
|
UnitDir |
getUnitDir()
Returns the enclosing UnitDir instance that created
this segment. |
boolean |
isPurgeable()
Determines whether this instance is purgeable. |
protected SubFileChannel |
newSubFileChannelImpl(FileChannel entryFile,
long start,
long end,
boolean update)
Returns a SubFileChannel that updates the usage count. |
String |
toString()
Returns a concatenation of the simple class name together with the base ID and entry count. |
Methods inherited from class com.faunos.skwish.sys.BaseSegment |
---|
allocateWorkBuffer, append, close, commit, flush, generateNoise, getBaseId, getContentsSize, getEntryChannel, getEntryCount, getEntryInsertionChannel, getEntryPart, getEntryUpdateChannel, getNextId, getTotalSize, insertEntry, insertEntry, isAlive, isAutoCommit, isReadOnly, killNext, setAutoCommit, writeNewSegment |
Methods inherited from class com.faunos.skwish.Segment |
---|
contains, delete, delete, getEntry, getEntrySize, getEntryStream, hi, isDeleted, isDeleted, killNext, lo |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected UnitDir.Seg(FileChannel offsetFile, FileChannel entryFile) throws IOException
IOException
Method Detail |
---|
public void appendWithLock(UnitDir.Seg seg) throws IOException
SegmentStoreException
is thrown. Therefore, the caller will typically already own the
locks to be held before invoking this
method. On return, the locks are released, and if successful (no
exception raised), the argument seg
instance's
purgeable property is set to
true
.
This append implementation is designed to prevent a segment from
being appended (as either source or destination) while it is
concurrently involved in another append operation, and
from concurrent deletes in the source of an append.
src
instance's append lock is acquired,
then this (destination) instance's append lock,
and finally the src
instance's append-source
lock.
The locks held are categorized below (not in the order they are acquired).
IOException
isPurgeable()
,
getAppendSourceLock()
,
delete(long, int, boolean)
public boolean isPurgeable()
true
, if and only if this instance has been
appended to another UnitDir.Seg
instance.public Lock getAppendSourceLock()
appendWithLock(com.faunos.skwish.sys.mgr.UnitDir.Seg)
,
isPurgeable()
public Lock getAppendLock()
appendWithLock(com.faunos.skwish.sys.mgr.UnitDir.Seg)
public void delete(long id, int count, boolean purge) throws IOException
delete
in class BaseSegment
id
- the ID of the first entry to be deleted. Must be
a valid ID in this segment [baseId, baseId + entryCount)count
- the number of entries to be deleted. Specifies a
range of IDs to be deleted: [id, id + count). The range
of IDs must be valid entries within this segment; o.w.
an exception is raised.purge
- if true
, the contents of the deleted entries
are signaled to be purged (overwritten) immediately;
o.w. the contents will be deleted on the next time the segment is
compacted.
IOException
getAppendSourceLock()
public void append(BaseSegment segment, int maxIdGap) throws IOException
BaseSegment
segment
to this segment. The contents of entries
marked "deleted" are not appended to this segment. The segment's
base ID is expected to be close to, but ≥ the next ID of
this segment. The maxIdGap
parameter specifies minimum requirements
for the proximity of IDs in the segment to be appended.
The append
method is designed to support merging segments.
append
in class BaseSegment
IOException
BaseSegment.append(BaseSegment)
public void getEntry(long id, ByteBuffer out, ByteBuffer workBuffer) throws IOException
Segment
out
buffer.
getEntry
in class BaseSegment
out
- the buffer into which the contents are written. Its
remaining bytes must be large enough; o.w., an exception is raised.workBuffer
- a work buffer used internally to read offsets. The minimum
capacity of this work buffer must be 16
IOException
UnitDir.getUsageCount()
public long getEntrySize(long id, ByteBuffer workBuffer) throws IOException
Segment
getEntrySize
in class BaseSegment
IOException
UnitDir.getUsageCount()
protected SubFileChannel newSubFileChannelImpl(FileChannel entryFile, long start, long end, boolean update) throws IOException
SubFileChannel
that updates the usage count.
newSubFileChannelImpl
in class BaseSegment
IOException
UnitDir.getUsageCount()
public UnitDir getUnitDir()
UnitDir
instance that created
this segment.
public boolean covers(UnitDir.Seg segment)
segment
. This instance covers another if the range of
IDs in the other segment is also contained in this segment, and if
this segment's number of entries is greater than that of the other.
A better way to say this: a segment covers another
segment if its set of entry IDs is a proper superset of that of the
other.
public String getName()
public String toString()
Segment
toString
in class Segment
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |