public void FinalizeInsert(StreamRange range) { UnlockNode(range); var pHeader = (BTreeHeader *)_HeaderRange.Pointer; Interlocked.Increment(ref pHeader->ItemCount); }
public void UnlockNode(StreamRange range) { var pNode = (BTreeNode *)range.Pointer; if (pNode->IsValid != 0) { throw new InvalidDataException(); } pNode->IsValid = 1; }
public uint GetValueDataTotalBytes(StreamRange nodeRange, long valueIndex, ushort keyType) { unchecked { var pEntry = (BTreeValue *)(nodeRange.Pointer + BTreeNode.OffsetOfValues + (valueIndex * BTreeValue.Size)); if (pEntry->KeyType != keyType) { throw new InvalidDataException(); } return(pEntry->DataLength + pEntry->ExtraDataBytes); } }
public BTreeValue *LockValue(StreamRange nodeRange, long valueIndex, ushort keyType) { unchecked { var pEntry = (BTreeValue *)(nodeRange.Pointer + BTreeNode.OffsetOfValues + (valueIndex * BTreeValue.Size)); if (pEntry->KeyType != keyType) { throw new InvalidDataException(); } pEntry->KeyType = 0; return(pEntry); } }
public BTree(StreamSource storage, string prefix) { Storage = storage; Prefix = prefix; IndexStream = Storage.Open(prefix + "index"); KeyStream = Storage.Open(prefix + "keys"); DataStream = Storage.Open(prefix + "data"); VersionCheck(IndexStream); VersionCheck(KeyStream); VersionCheck(DataStream); bool needInit = IndexStream.Length < BTreeHeader.Size; IndexStream.LengthChanging += IndexStream_LengthChanging; IndexStream.LengthChanged += IndexStream_LengthChanged; DataStream.LengthChanging += DataStream_LengthChanging; DataStream.LengthChanged += DataStream_LengthChanged; _GetKeyOfEntry = ReadKey; _HeaderRange = IndexStream.AccessRangeUncached(0, BTreeHeader.Size); if (needInit) { InitializeBTree(); } _FreelistBucketLocks = new object[FreelistIndex.BucketCount]; for (int i = 0; i < _FreelistBucketLocks.Length; i++) { _FreelistBucketLocks[i] = new object(); } EnsureFreelistExists(); }
void IndexStream_LengthChanged(object sender, EventArgs e) { _HeaderRange = IndexStream.AccessRangeUncached(0, BTreeHeader.Size); }
public void WriteNewKey(StreamRange nodeRange, uint valueIndex, TangleKey key) { long position = BTreeNode.OffsetOfValues + (valueIndex * BTreeValue.Size); WriteNewKey((BTreeValue *)(nodeRange.Pointer + position), key); }