示例#1
0
 private void LoadLastTermAndIndex()
 {
     using (var tx = _env.BeginReadOnlyTransaction())
     {
         LoadLastTermAndIndex(tx);
     }
 }
示例#2
0
        public void CanSaveAndReadString()
        {
            string key   = "jam!";
            string value = "jim!";

            using (var db = _env.OpenDatabase(DatabaseName, new DatabaseConfig(DbFlags.Create)))
            {
                using (var tx = _env.BeginTransaction())
                {
                    tx.Put(db, key, value);
                    tx.Commit();
                }

                using (var tx = _env.BeginReadOnlyTransaction())
                {
                    Bufferable b       = default;
                    var        success = tx.TryGet(db, key, out b);
                    Assert.True(success);
                    Assert.Equal(value, b);
                }
            }
        }
        public long GetTotalAllocated(int bucketIndex = -1)
        {
            using (var txn = _env.BeginReadOnlyTransaction())
                using (var aC = _allocatedDb.OpenReadOnlyCursor(txn))
                {
                    BufferRef lastAllocated  = default;
                    var       totalAllocated = 0L;

                    if (bucketIndex == -1)
                    {
                        byte bucketIndexByte = 0;
                        if (aC.TryGet(ref bucketIndexByte, ref lastAllocated, CursorGetOption.First))
                        {
                            var dataSize = SharedMemoryPool.BucketIndexToBufferSize(bucketIndexByte, _pageSize);
                            totalAllocated += dataSize * (long)aC.Count();

                            while (aC.TryGet(ref bucketIndexByte, ref lastAllocated, CursorGetOption.NextNoDuplicate))
                            {
                                dataSize        = SharedMemoryPool.BucketIndexToBufferSize(bucketIndex, _pageSize);
                                totalAllocated += dataSize * (long)aC.Count();
                            }
                        }
                    }
                    else
                    {
                        BufferRef.EnsureBucketIndexInRange(bucketIndex);
                        var bucketIndexByte = (byte)bucketIndex;
                        if (aC.TryGet(ref bucketIndexByte, ref lastAllocated, CursorGetOption.Set))
                        {
                            var dataSize = SharedMemoryPool.BucketIndexToBufferSize(bucketIndex, _pageSize);
                            totalAllocated += dataSize * (long)aC.Count();
                        }
                    }

                    _lastTotalSize = totalAllocated;
                    return(totalAllocated);
                }
        }
示例#4
0
            private void ReadOffsetPosition()
            {
                using (var txn = env.BeginReadOnlyTransaction())
                    using (var cursor = db.OpenReadOnlyCursor(txn))
                    {
                        var key    = OffsetKey;
                        var buffer = ArrayPool <byte> .Shared.Rent(8);

                        var value = new DirectBuffer(buffer);
                        if (cursor.TryGet(ref key, ref value, CursorGetOption.Last))
                        {
                            this.offset = BinaryPrimitives.ReadUInt64LittleEndian(value.Span);
                        }
                    }
            }
示例#5
0
 public ReadOnlyTransaction OpenReadOnlyTransaction()
 {
     ThrowIfDisposed();
     return(new ReadOnlyTransaction(environment.BeginReadOnlyTransaction(), databasesHolder, indexesHolder));
 }