Class Segment
- java.lang.Object
-
- org.apache.iotdb.db.metadata.mtree.store.disk.schemafile.Segment
-
-
Field Summary
-
Fields inherited from interface org.apache.iotdb.db.metadata.mtree.store.disk.schemafile.ISegment
SEG_HEADER_SIZE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddelete()voidextendsTo(java.nio.ByteBuffer newBuffer)This method will write info into a buffer equal or larger to existed one.java.util.Queue<IMNode>getAllRecords()java.nio.ByteBuffergetBufferCopy()java.nio.ByteBuffergetInnerBuffer()java.util.List<org.apache.iotdb.tsfile.utils.Pair<java.lang.String,java.lang.Short>>getKeyOffsetList()longgetNextSegAddress()longgetPrevSegAddress()java.nio.ByteBuffergetRecord(java.lang.String key)IMNodegetRecordAsIMNode(java.lang.String key)get a MNode by its name or aliasshortgetSpareSize()booleanhasRecordAlias(java.lang.String alias)booleanhasRecordKey(java.lang.String key)static ISegmentinitAsSegment(java.nio.ByteBuffer buffer)intinsertRecord(java.lang.String key, java.nio.ByteBuffer buf)check whether enough space, notice that pairLength including 3 parts: [var length] key string itself, [int, 4 bytes] length of key string, [short, 2 bytes] key addressjava.lang.Stringinspect()static ISegmentloadAsSegment(java.nio.ByteBuffer buffer)intremoveRecord(java.lang.String key)voidsetNextSegAddress(long nextSegAddress)voidsetPrevSegAddress(long prevSegAddress)shortsize()voidsyncBuffer()Records are always sync with buffer, but header and key-address list are not.java.lang.StringtoString()intupdateRecord(java.lang.String key, java.nio.ByteBuffer uBuffer)protected voidupdateRecordSegAddr(java.lang.String key, long newSegAddr)
-
-
-
Constructor Detail
-
Segment
public Segment(java.nio.ByteBuffer buffer, boolean override)Init Segment with a buffer, which contains all information about this segmentFor a page no more than 16 kib, a signed short is enough to index all bytes inside a segment.
Segment Structure:
- 25 byte: header
- 1 short: length, segment length
- 1 short: freeAddr, start offset of records
- 1 short: recordNum, amount of records in this segment
- 1 short: pairLength, length of key-address in bytes
- 1 long (8 bytes): prevSegIndex, previous segment index
- 1 long (8 bytes): nextSegIndex, next segment index
- 1 bit: delFlag, delete flag
(--- checksum, parent record address, max/min record key may be contained further ---)- var length: key-address pairs, begin at 25 bytes offset, length of pairLength
... empty space ...- var length: records
-
Segment
public Segment(java.nio.ByteBuffer buffer)
-
Segment
public Segment(int size)
-
-
Method Detail
-
initAsSegment
public static ISegment initAsSegment(java.nio.ByteBuffer buffer)
-
loadAsSegment
public static ISegment loadAsSegment(java.nio.ByteBuffer buffer)
-
insertRecord
public int insertRecord(java.lang.String key, java.nio.ByteBuffer buf) throws RecordDuplicatedExceptionDescription copied from interface:ISegmentcheck whether enough space, notice that pairLength including 3 parts: [var length] key string itself, [int, 4 bytes] length of key string, [short, 2 bytes] key address- Specified by:
insertRecordin interfaceISegment- Returns:
- -1 for segment overflow, otherwise for spare space
- Throws:
RecordDuplicatedException
-
getRecordAsIMNode
public IMNode getRecordAsIMNode(java.lang.String key) throws org.apache.iotdb.commons.exception.MetadataException
Description copied from interface:ISegmentget a MNode by its name or alias- Specified by:
getRecordAsIMNodein interfaceISegment- Parameters:
key- name or alias of the target node- Returns:
- node instance
- Throws:
org.apache.iotdb.commons.exception.MetadataException
-
hasRecordKey
public boolean hasRecordKey(java.lang.String key)
- Specified by:
hasRecordKeyin interfaceISegment
-
hasRecordAlias
public boolean hasRecordAlias(java.lang.String alias)
- Specified by:
hasRecordAliasin interfaceISegment
-
getAllRecords
public java.util.Queue<IMNode> getAllRecords() throws org.apache.iotdb.commons.exception.MetadataException
- Specified by:
getAllRecordsin interfaceISegment- Throws:
org.apache.iotdb.commons.exception.MetadataException
-
updateRecord
public int updateRecord(java.lang.String key, java.nio.ByteBuffer uBuffer) throws SegmentOverflowException, RecordDuplicatedException- Specified by:
updateRecordin interfaceISegment- Parameters:
key- name of the record, not the aliasuBuffer- content of the updated record- Returns:
- index of keyAddressList, -1 for not found, exception for space run out
- Throws:
SegmentOverflowException- if segment runs out of memoryRecordDuplicatedException
-
removeRecord
public int removeRecord(java.lang.String key)
- Specified by:
removeRecordin interfaceISegment
-
syncBuffer
public void syncBuffer()
Description copied from interface:ISegmentRecords are always sync with buffer, but header and key-address list are not. This method sync these values to the buffer.- Specified by:
syncBufferin interfaceISegment
-
getSpareSize
public short getSpareSize()
- Specified by:
getSpareSizein interfaceISegment
-
extendsTo
public void extendsTo(java.nio.ByteBuffer newBuffer)
Description copied from interface:ISegmentThis method will write info into a buffer equal or larger to existed one. There is no need to call sync before this method, since it will flush header and key-offset list directly.
-
getPrevSegAddress
public long getPrevSegAddress()
- Specified by:
getPrevSegAddressin interfaceISegment
-
getNextSegAddress
public long getNextSegAddress()
- Specified by:
getNextSegAddressin interfaceISegment
-
setPrevSegAddress
public void setPrevSegAddress(long prevSegAddress)
- Specified by:
setPrevSegAddressin interfaceISegment
-
setNextSegAddress
public void setNextSegAddress(long nextSegAddress)
- Specified by:
setNextSegAddressin interfaceISegment
-
getBufferCopy
public java.nio.ByteBuffer getBufferCopy()
-
updateRecordSegAddr
protected void updateRecordSegAddr(java.lang.String key, long newSegAddr)
-
toString
public java.lang.String toString()
-
getRecord
public java.nio.ByteBuffer getRecord(java.lang.String key)
-
getInnerBuffer
public java.nio.ByteBuffer getInnerBuffer()
-
getKeyOffsetList
public java.util.List<org.apache.iotdb.tsfile.utils.Pair<java.lang.String,java.lang.Short>> getKeyOffsetList()
-
-