public class NodeSerializer extends Object
An instance of this class is used to serialize and de-serialize the
ILeafDatas of an
and non-leaf records have different serialization formats, but their leading
bytes use the same format so that you can tell by inspection whether a buffer
contains a leaf or a non-leaf node. The header of the record uses a fixed
length format so that some fields can be tested without full
de-serialization, especially whether the record contains a leaf vs a node.
This fixed record also makes it possible to update some fields in the header
once the entire record has been serialized, including the checksum, the #of
bytes in the serialized record, and the prior/next addresses for leaves.
The methods defined by this class all work with
ByteBuffers. On read,
the buffer must be positioned to the start of the data to be read. After a
read, the buffer will be positioned to the first byte after the data read. If
there is insufficient data available in the buffer then an
BufferUnderflowException will be thrown. On write, the data will be
written on an internal buffer whose size is automatically extended. The write
buffer is reused for each write and quickly achieves a maximum size for any
|Modifier and Type||Field and Description|
The default initial capacity multiplier for the (de-)serialization buffer.
|Constructor and Description|
|Modifier and Type||Method and Description|
Releases any buffers.
This method is no longer used since I refactored the
Encode a node or leaf and return a coded instance of the persistent data for that node or leaf backed by an exact fit byte (NOT thread-safe).
Update the serialization of a leaf to set the prior and next leaf references and change its serialization type from
protected final INodeFactory nodeFactory
public static final transient int DEFAULT_BUFFER_CAPACITY_PER_ENTRY
public NodeSerializer(IAddressManager addressManager, INodeFactory nodeFactory, int branchingFactor, int initialBufferCapacity, IndexMetadata indexMetadata, boolean readOnly, IRecordCompressorFactory<?> recordCompressorFactory)
nodeFactory- An object that knows how to construct
branchingFactor- The branching factor for target B+Tree. For the
IndexSegmentBuilderthis should be the branching factor of the
IndexSegmentwhich is being generated. Otherwise it is the branching factor of the
initialBufferCapacity- The initial capacity for internal buffer used to serialize nodes and leaves. The buffer will be resized as necessary until it is sufficient for the records being serialized for the
BTree. When zero (0), a default is used. A non-zero value is worth specifying only when the actual buffer size is consistently less than the default for some
IndexMetadatarecord for the index.
trueIFF the caller is asserting that they WILL NOT attempt to serialize any nodes or leaves using this
IRecordCompressorFactoryshould either be used here or moved into the
IAddressManageris not used any more. It was used by the
public void close()
NodeSerializeris used again.
public IAbstractNodeData decode(ByteBuffer buf)
ILeafDatarecord, wrapping the underlying data record (thread-safe). The decision to decode as an
ILeafDatainstance is made based on inspection of the first byte byte in the supplied buffer, which codes for a node, leaf, or linked-leaf.
public AbstractNode<?> wrap(AbstractBTree btree, long addr, IAbstractNodeData data)
ILeafDatainstance as a
Leaf. This DOES NOT set the parent of the new
btree- The owning B+Tree.
addr- The address of the data record in the backing store.
data- The data record.
public <T extends IAbstractNodeData> T encodeLive(T node)
node- The node or leaf.
public AbstractFixedByteArrayBuffer encode(IAbstractNodeData node)
IndexSegmentBuilderto optionally stuff the generated nodes and leaves into the cache. It still works but it might go away in the future.
encodeLive(IAbstractNodeData)which is used when the written node or leaf will not be reused, e.g., by the
IndexSegmentBuilder. The operation writes on an internal buffer which is automatically extended as required.
node- The node or leaf.
public void updateLeaf(ByteBuffer b, long priorAddr, long nextAddr)
Note: In order to use this method to write linked leaves on the store you have to either write behind at a pre-determined address on the store or settle for writing only the prior or the next leaf address, but not both. It is up to the caller to perform these tricks. All this method does is to touch up the serialized record.
Note: This method has NO side-effects on the position or
limit of the caller's
b- The serialization leaf.
priorAddr- The address of the previous leaf in key order,
0Lif it is known that there is no previous leaf, and
-1Lif either: (a) it is not known whether there is a previous leaf; or (b) it is known but the address of that leaf is not known to the caller.
nextAddr- The address of the next leaf in key order,
0Lif it is known that there is no next leaf, and
-1Lif either: (a) it is not known whether there is a next leaf; or (b) it is known but the address of that leaf is not known to the caller.
Copyright © 2006-2015 SYSTAP, LLC. All Rights Reserved.