DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Index.IndexBlock Class Reference

Public Member Functions

 IndexBlock (IndexSetStore indexSetStore, int indexNum, int blockSize, long startOffset)
 
long[] GetBlockPointers ()
 
IIndex CreateIndex ()
 
void AddReference ()
 
void RemoveReference ()
 
void MarkAsDeleted ()
 
void AddDeletedArea (long pointer)
 

Properties

IndexBlock Parent [get, set]
 
bool IsFreed [get, private set]
 
bool IsDeleted [get, private set]
 
int BlockSize [get, private set]
 
long StartOffset [get, private set]
 

Private Member Functions

IEnumerable< IMappedBlockCreateMappedBlocks ()
 
bool DeleteBlockChain ()
 

Private Attributes

readonly IndexSetStore indexSetStore
 
readonly int indexNum
 
readonly long blockEntries
 
List< int > deletedAreas
 
int refCount
 

Detailed Description

Definition at line 25 of file IndexBlock.cs.

Constructor & Destructor Documentation

Deveel.Data.Index.IndexBlock.IndexBlock ( IndexSetStore  indexSetStore,
int  indexNum,
int  blockSize,
long  startOffset 
)
inline

Definition at line 34 of file IndexBlock.cs.

34  {
36  this.indexNum = indexNum;
37  BlockSize = blockSize;
38  StartOffset = startOffset;
39 
40  // Read the index count
41  var indexBlockArea = indexSetStore.Store.GetArea(startOffset);
42  indexBlockArea.Position = 8;
43  blockEntries = indexBlockArea.ReadInt8();
44 
45  refCount = 0;
46  }
readonly IndexSetStore indexSetStore
Definition: IndexBlock.cs:26
long Position
Returns or sets the current position of the pointer within the area.
Definition: IArea.cs:48
readonly long blockEntries
Definition: IndexBlock.cs:28
IArea GetArea(long id, bool readOnly)
Returns an object that allows for the contents of an area (represented by the id parameter) to be Re...

Member Function Documentation

void Deveel.Data.Index.IndexBlock.AddDeletedArea ( long  pointer)
inline

Definition at line 185 of file IndexBlock.cs.

185  {
186  lock (this) {
187  if (deletedAreas == null) {
188  deletedAreas = new List<int>();
189  }
190 
191  deletedAreas.Add((int)pointer);
192  }
193  }
void Deveel.Data.Index.IndexBlock.AddReference ( )
inline

Definition at line 142 of file IndexBlock.cs.

142  {
143  lock (this) {
144  if (IsFreed)
145  throw new Exception("Assertion failed: Block was freed.");
146 
147  ++refCount;
148  }
149  }
IIndex Deveel.Data.Index.IndexBlock.CreateIndex ( )
inline

Definition at line 109 of file IndexBlock.cs.

109  {
110  // Create the MappedListBlock objects for this view
111  var blocks = CreateMappedBlocks().Cast<IIndexBlock<int>>();
112  // And return the Index
113  return new StoreIndex(indexSetStore, indexNum, BlockSize, blocks);
114  }
readonly IndexSetStore indexSetStore
Definition: IndexBlock.cs:26
IEnumerable< IMappedBlock > CreateMappedBlocks()
Definition: IndexBlock.cs:81
IEnumerable<IMappedBlock> Deveel.Data.Index.IndexBlock.CreateMappedBlocks ( )
inlineprivate

Definition at line 81 of file IndexBlock.cs.

81  {
82  // Create an area for the index block pointer
83  var indexBlockArea = indexSetStore.Store.GetArea(StartOffset);
84 
85  // First create the list of block entries for this list
86  var blocks = new IMappedBlock[(int) blockEntries];
87  if (blockEntries != 0) {
88  indexBlockArea.Position = 16;
89  for (int i = 0; i < blockEntries; ++i) {
90  // NOTE: We cast to 'int' here because of internal limitations.
91  var firstEntry = indexBlockArea.ReadInt8();
92  var lastEntry = indexBlockArea.ReadInt8();
93  var blockPointer = indexBlockArea.ReadInt8();
94  var typeSize = indexBlockArea.ReadInt4();
95 
96  //TODO: check this...
97  // size is the first 24 bits (max size = 16MB)
98  int elementCount = typeSize & 0x0FFF;
99  byte type = (byte) (ByteBuffer.URShift(typeSize, 24) & 0x0F);
100 
101  blocks[i] = StoreIndex.NewMappedBlock(indexSetStore, firstEntry, lastEntry, blockPointer, elementCount, type,
102  BlockSize);
103  }
104  }
105 
106  return blocks;
107  }
readonly IndexSetStore indexSetStore
Definition: IndexBlock.cs:26
long Position
Returns or sets the current position of the pointer within the area.
Definition: IArea.cs:48
readonly long blockEntries
Definition: IndexBlock.cs:28
static int URShift(int number, int bits)
Operates a shift on the given integer by the number of bits specified.
Definition: ByteBuffer.cs:277
A wrapper for an array of byte.
Definition: ByteBuffer.cs:27
IArea GetArea(long id, bool readOnly)
Returns an object that allows for the contents of an area (represented by the id parameter) to be Re...
bool Deveel.Data.Index.IndexBlock.DeleteBlockChain ( )
inlineprivate

Definition at line 116 of file IndexBlock.cs.

116  {
117  bool parentDeleted = true;
118  if (Parent != null) {
119  parentDeleted = Parent.DeleteBlockChain();
120  if (parentDeleted) {
121  Parent = null;
122  }
123  }
124 
125  // If the parent is deleted,
126  if (parentDeleted) {
127  // Can we delete this block?
128  if (refCount <= 0) {
129  if (IsDeleted && deletedAreas != null) {
131  }
132  deletedAreas = null;
133  } else {
134  // We can't delete this block so return false
135  return false;
136  }
137  }
138 
139  return parentDeleted;
140  }
readonly IndexSetStore indexSetStore
Definition: IndexBlock.cs:26
void DeleteAreas(IEnumerable< int > deletedAreas)
long [] Deveel.Data.Index.IndexBlock.GetBlockPointers ( )
inline

Definition at line 58 of file IndexBlock.cs.

58  {
59  // Create an area for the index block pointer
60  var indexBlockArea = indexSetStore.Store.GetArea(StartOffset);
61 
62  // First create the list of block entries for this list
63  long[] blocks = new long[(int)blockEntries];
64  if (blockEntries != 0) {
65  indexBlockArea.Position = 16;
66 
67  for (int i = 0; i < blockEntries; ++i) {
68  // NOTE: We cast to 'int' here because of internal limitations.
69  indexBlockArea.ReadInt8();
70  indexBlockArea.ReadInt8();
71  long elementP = indexBlockArea.ReadInt8();
72  indexBlockArea.ReadInt4();
73 
74  blocks[i] = elementP;
75  }
76  }
77 
78  return blocks;
79  }
readonly IndexSetStore indexSetStore
Definition: IndexBlock.cs:26
long Position
Returns or sets the current position of the pointer within the area.
Definition: IArea.cs:48
readonly long blockEntries
Definition: IndexBlock.cs:28
IArea GetArea(long id, bool readOnly)
Returns an object that allows for the contents of an area (represented by the id parameter) to be Re...
void Deveel.Data.Index.IndexBlock.MarkAsDeleted ( )
inline

Definition at line 179 of file IndexBlock.cs.

179  {
180  lock (this) {
181  IsDeleted = true;
182  }
183  }
void Deveel.Data.Index.IndexBlock.RemoveReference ( )
inline

Definition at line 151 of file IndexBlock.cs.

151  {
152  bool pendingDelete = false;
153  lock (this) {
154  --refCount;
155  if (refCount <= 0) {
156  if (IsFreed)
157  throw new Exception("Assertion failed: remove reference called too many times.");
158 
159  if (!IsDeleted && deletedAreas != null)
160  throw new Exception("Assertion failed: not deleted and with deleted areas");
161 
162  IsFreed = true;
163 
164  if (IsDeleted) {
166  // Delete these areas
167  pendingDelete = true;
168  }
169  }
170  } // lock(this)
171 
172  if (pendingDelete) {
173  lock (indexSetStore.Store) {
175  }
176  }
177  }
readonly IndexSetStore indexSetStore
Definition: IndexBlock.cs:26
void AddDeletedArea(long pointer)
Definition: IndexBlock.cs:185

Member Data Documentation

readonly long Deveel.Data.Index.IndexBlock.blockEntries
private

Definition at line 28 of file IndexBlock.cs.

List<int> Deveel.Data.Index.IndexBlock.deletedAreas
private

Definition at line 30 of file IndexBlock.cs.

readonly int Deveel.Data.Index.IndexBlock.indexNum
private

Definition at line 27 of file IndexBlock.cs.

readonly IndexSetStore Deveel.Data.Index.IndexBlock.indexSetStore
private

Definition at line 26 of file IndexBlock.cs.

int Deveel.Data.Index.IndexBlock.refCount
private

Definition at line 32 of file IndexBlock.cs.

Property Documentation

int Deveel.Data.Index.IndexBlock.BlockSize
getprivate set

Definition at line 54 of file IndexBlock.cs.

bool Deveel.Data.Index.IndexBlock.IsDeleted
getprivate set

Definition at line 52 of file IndexBlock.cs.

bool Deveel.Data.Index.IndexBlock.IsFreed
getprivate set

Definition at line 50 of file IndexBlock.cs.

IndexBlock Deveel.Data.Index.IndexBlock.Parent
getset

Definition at line 48 of file IndexBlock.cs.

long Deveel.Data.Index.IndexBlock.StartOffset
getprivate set

Definition at line 56 of file IndexBlock.cs.


The documentation for this class was generated from the following file: