org.terracotta.offheapstore.disk.storage
Class AATreeFileAllocator

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<T>
          extended by org.terracotta.offheapstore.util.AATreeSet<org.terracotta.offheapstore.disk.storage.Region>
              extended by org.terracotta.offheapstore.disk.storage.AATreeFileAllocator
All Implemented Interfaces:
Iterable<org.terracotta.offheapstore.disk.storage.Region>, Collection<org.terracotta.offheapstore.disk.storage.Region>, Set<org.terracotta.offheapstore.disk.storage.Region>, SortedSet<org.terracotta.offheapstore.disk.storage.Region>

public class AATreeFileAllocator
extends AATreeSet<org.terracotta.offheapstore.disk.storage.Region>

An augmented AA tree based allocator.

This allocator maintains an augmented AA tree of free regions. Tree nodes are augmented with the size of the maximum and minimum contiguous free region linked beneath them in the tree. Regions being freed are merged with adjacent free regions and the tree structure updated to reflect the resultant region.

Allocations are performed in a very approximate best fit manner. Assuming that there is a large enough free region in the tree, tree navigation decisions proceed as follows:

  1. if the requested size is smaller than or equal to the smallest contiguous region then find the smallest contiguous region and use it
  2. if the current node is perfectly sized then use it
  3. pick the child with the smallest contiguous subnode that will hold us - and then go to 2
  4. if no such child exists use the current node

This allocator will experience bad fragmentation affects when not used with uniformly sized allocations calls. Since the AA Tree is stored in the Java object heap this can lead to excessive heap usage.

Author:
Chris Dennis

Nested Class Summary
 
Nested classes/interfaces inherited from class org.terracotta.offheapstore.util.AATreeSet
AATreeSet.AbstractTreeNode<E extends Comparable<? super E>>, AATreeSet.Node<E extends Comparable<? super E>>
 
Constructor Summary
AATreeFileAllocator(long size)
          Create an abstract allocator using the given buffer source and initial size.
AATreeFileAllocator(long size, DataInput input)
           
 
Method Summary
 long allocate(long size)
           
 long capacity()
           
 org.terracotta.offheapstore.disk.storage.Region find(Object o)
           
 void free(long address, long length)
           
 long occupied()
           
 org.terracotta.offheapstore.disk.storage.Region removeAndReturn(Object o)
           
 String toString()
          
 
Methods inherited from class org.terracotta.offheapstore.util.AATreeSet
add, clear, comparator, first, getRoot, headSet, isEmpty, iterator, last, remove, size, subSet, tailSet
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, contains, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

AATreeFileAllocator

public AATreeFileAllocator(long size)
Create an abstract allocator using the given buffer source and initial size.

This initial size will be used to size the buffer returned from the clear call.

Parameters:
size - initial buffer size

AATreeFileAllocator

public AATreeFileAllocator(long size,
                           DataInput input)
                    throws IOException
Throws:
IOException
Method Detail

allocate

public long allocate(long size)

free

public void free(long address,
                 long length)

removeAndReturn

public org.terracotta.offheapstore.disk.storage.Region removeAndReturn(Object o)
Overrides:
removeAndReturn in class AATreeSet<org.terracotta.offheapstore.disk.storage.Region>

find

public org.terracotta.offheapstore.disk.storage.Region find(Object o)
Overrides:
find in class AATreeSet<org.terracotta.offheapstore.disk.storage.Region>

occupied

public long occupied()

capacity

public long capacity()

toString

public String toString()

Overrides:
toString in class AbstractCollection<org.terracotta.offheapstore.disk.storage.Region>


Copyright © 2015. All Rights Reserved.