public static IMappedBlock NewMappedBlock(IndexSetStore indexSetStore, long firstEntry, long lastEntry,
                                           long blockPointer,
                                           int size, byte compactType, int blockSize)
 {
     return(new MappedBlock(indexSetStore, firstEntry, lastEntry, blockPointer, size, compactType,
                            blockSize));
 }
            public SnapshotIndexSet(IndexSetStore indexSetStore, IndexBlock[] blocks)
            {
                this.indexSetStore = indexSetStore;
                indexBlocks        = blocks;

                // Not disposed.
                disposed = false;
            }
            public Index(IndexSetStore indexSetStore, int indexNumber, int maxBlockSize,
                         IEnumerable <ICollectionBlock <SqlObject, long> > blocks)
                : base(blocks)
            {
                IndexSetStore = indexSetStore;
                IndexNumber   = indexNumber;
                MaxBlockSize  = maxBlockSize;

                deletedBlocks = new List <IMappedBlock>();
            }
Beispiel #4
0
        public void CreateAndOpenStore()
        {
            var indexSetStore = new IndexSetStore(store);

            var pointer = indexSetStore.Create();

            Assert.True(pointer >= 0);

            indexSetStore.Open(pointer);

            indexSetStore.Dispose();
        }
                public MappedBlock(IndexSetStore indexSetStore, long firstEntry, long lastEntry, long blockPointer,
                                   int size, byte compactType, int maxBlockSize)
                {
                    IndexSetStore = indexSetStore;
                    FirstEntry    = firstEntry;
                    LastEntry     = lastEntry;
                    BlockPointer  = blockPointer;
                    CompactType   = compactType;

                    this.maxBlockSize = maxBlockSize;
                    Count             = size;
                    BaseArray         = null;
                }
            internal IndexBlock(IndexSetStore indexSetStore, int indexNum, int blockSize, long startOffset)
            {
                this.indexSetStore = indexSetStore;
                this.indexNum      = indexNum;
                BlockSize          = blockSize;
                StartOffset        = startOffset;

                // Read the index count
                var indexBlockArea = indexSetStore.Store.GetArea(startOffset);

                indexBlockArea.Position = 8;
                blockEntries            = indexBlockArea.ReadInt64();

                refCount = 0;
            }
            private void Dispose(bool disposing)
            {
                if (!disposed)
                {
                    if (disposing)
                    {
                        if (deletedBlocks != null)
                        {
                            deletedBlocks.Clear();
                        }
                    }

                    IndexSetStore = null;
                    deletedBlocks = null;
                    disposed      = true;
                }
            }
Beispiel #8
0
        public void GetSnapshotIndex()
        {
            var indexSetStore = new IndexSetStore(store);

            var pointer = indexSetStore.Create();

            indexSetStore.Open(pointer);

            var indexSet = indexSetStore.GetSnapshotIndex();

            Assert.NotNull(indexSet);
            Assert.Empty(indexSet);

            indexSet.Dispose();

            indexSetStore.Dispose();
        }
        public void Dispose()
        {
            if (FieldCache != null)
            {
                FieldCache.Clear();
            }

            if (headerArea != null)
            {
                headerArea.Dispose();
            }

            if (recordList != null)
            {
                recordList.Dispose();
            }

            if (Registries != null)
            {
                Registries.Dispose();
            }

            if (indexSetStore != null)
            {
                indexSetStore.Dispose();
            }

            if (Store != null)
            {
                if (StoreSystem.CloseStore(Store))
                {
                    Store.Dispose();
                }
            }

            headerArea    = null;
            recordList    = null;
            Registries    = null;
            indexSetStore = null;
        }
        private void SetupInitialStore()
        {
            byte[] tableInfoBuf;

            using (var stream = new MemoryStream()) {
                var writer = new BinaryWriter(stream, Encoding.Unicode);
                writer.Write(1);
                TableInfoSerializer.Serialize(TableInfo, writer);

                tableInfoBuf = stream.ToArray();
            }

            byte[] indexSetInfoBuf;

            using (var stream = new MemoryStream()) {
                var writer = new BinaryWriter(stream, Encoding.Unicode);
                writer.Write(1);

                IndexSetInfoSerializer.Serialize(IndexSetInfo, writer);

                indexSetInfoBuf = stream.ToArray();
            }

            try {
                Store.Lock();

                // Allocate an 80 byte header
                using (var headerWriter = Store.CreateArea(80)) {
                    long headerPointer = headerWriter.Id;

                    // Allocate space to store the DataTableInfo serialization
                    using (var dataTableDefWriter = Store.CreateArea(tableInfoBuf.Length)) {
                        long tableInfoOffset = dataTableDefWriter.Id;

                        // Allocate space to store the DataIndexSetInfo serialization
                        using (var indexSetWriter = Store.CreateArea(indexSetInfoBuf.Length)) {
                            long indexSetInfoPointer = indexSetWriter.Id;

                            // Allocate space for the list header
                            listHeaderOffset = recordList.Create();
                            recordList.WriteDeleteHead(-1);
                            firstDeleteChainRecord = -1;

                            // Create the index store
                            indexSetStore     = new IndexSetStore(Store);
                            indexHeaderOffset = indexSetStore.Create();

                            // Write the main header
                            headerWriter.Write((int)1);                              // Version
                            headerWriter.Write(TableId);                             // table id
                            headerWriter.Write(sequenceId);                          // initial sequence id
                            headerWriter.Write(tableInfoOffset);                     // pointer to DataTableInfo
                            headerWriter.Write(indexSetInfoPointer);                 // pointer to DataIndexSetInfo
                            headerWriter.Write(indexHeaderOffset);                   // index header pointer
                            headerWriter.Write(listHeaderOffset);                    // list header pointer
                            headerWriter.Flush();

                            // Write the table info
                            dataTableDefWriter.Write(tableInfoBuf, 0, tableInfoBuf.Length);
                            dataTableDefWriter.Flush();

                            // Write the index set info
                            indexSetWriter.Write(indexSetInfoBuf, 0, indexSetInfoBuf.Length);
                            indexSetWriter.Flush();

                            // Set the pointer to the header input the reserved area.
                            using (var fixedArea = Store.GetArea(-1)) {
                                fixedArea.Write(headerPointer);
                                fixedArea.Flush();
                            }

                            // Set the header area
                            headerArea = Store.GetArea(headerPointer);
                        }
                    }
                }
            } finally {
                Store.Unlock();
            }
        }