/* * * Layout: [ Doc Guid (16 bytes) | PageLink[0] (5 bytes) | PageLink[1] (5 bytes) ] --> 26 bytes * We can fit 157 in a 4k page. Gives us 6 ranks (126 entries) -> 3276 bytes * Our pages are currently 4061 bytes, so we have plenty of spare space if we can find useful metadata to store. * * We assume but don't store a root page with guid {127,127...,127}. The first two entries are 'left' and 'right' on the second level. * */ public IndexPage() { _links = new VersionedLink[EntryCount]; for (int i = 0; i < EntryCount; i++) { _links[i] = new VersionedLink(); } _docIds = new Guid[EntryCount]; }
[NotNull] private VersionedLink GetLink(int headOffset) { var result = new VersionedLink(); lock (_fslock) { _fs.Seek(MAGIC_SIZE + (VersionedLink.ByteSize * headOffset), SeekOrigin.Begin); result.Defrost(_fs); } return(result); }
private void SetLink(int headOffset, VersionedLink value) { if (value == null) { throw new Exception("Attempted to set invalid header link"); } var strm = value.Freeze(); lock (_fslock) { _fs.Seek(MAGIC_SIZE + (VersionedLink.ByteSize * headOffset), SeekOrigin.Begin); strm.CopyTo(_fs); } }
/// <summary> /// Update a link to set an invalid link. Both versions of the link will be lost. /// Returns true if a change was made. False if the link was not found in this index page /// </summary> /// <param name="docId">ID of document to update</param> /// <returns></returns> public bool Remove(Guid docId) { // find the entry to update var index = Find(docId); if (index < 0 || index >= EntryCount) { return(false); // not found } if (_docIds[index] == ZeroDocId) { return(false); // not found } if (_docIds[index] != docId) { throw new Exception("IndexPage.Remove: Logic error"); } _links[index] = new VersionedLink(); // entirely reset return(true); }
public static void InitialiseDb([NotNull] Stream fs) { if (!fs.CanWrite) { throw new Exception("Tried to initialise a read-only stream"); } fs.Seek(0, SeekOrigin.Begin); foreach (var b in HEADER_MAGIC) { fs.WriteByte(b); } // write disabled links for the three core chains var indexVersion = new VersionedLink(); var pathLookupVersion = new VersionedLink(); var freeListVersion = new VersionedLink(); indexVersion.Freeze().CopyTo(fs); pathLookupVersion.Freeze().CopyTo(fs); freeListVersion.Freeze().CopyTo(fs); Flush(fs); }
private void SetFreeListLink(VersionedLink value) { SetLink(2, value); }
private void SetPathLookupLink(VersionedLink value) { SetLink(1, value); }
private void SetIndexPageLink(VersionedLink value) { SetLink(0, value); }