コード例 #1
0
ファイル: Store.cs プロジェクト: stuarthillary/sim-cluster
        IEnumerable <TOut> InternalScan <TOut>(LightningTransaction lt, FdbKeyRange range,
                                               Func <Slice, byte[], TOut> convert)
        {
            ushort x = 0;

            using (var c = lt.CreateCursor(_ld)) {
                if (!c.MoveToFirstAfter(range.Begin.GetBytes()))
                {
                    yield break;
                }

                var pair = c.Current;

                for (var i = 0; i < int.MaxValue; i++)
                {
                    var current = Slice.Create(pair.Key);
                    if (!range.Contains(current))
                    {
                        break;
                    }
                    x += 1;
                    yield return(convert(current, pair.Value));

                    if (!c.MoveNext())
                    {
                        break;
                    }
                    pair = c.Current;
                }
            }
        }
コード例 #2
0
 public IEnumerable <KeyValuePair <TKey, T> > List()
 {
     using (var c = _tx.CreateCursor(_db))
         while (c.MoveNext())
         {
             yield return(new KeyValuePair <TKey, T>(
                              _settings.DeserializeKey(c.Current.Key),
                              _settings.Deserialize(c.Current.Value)));
         }
 }
コード例 #3
0
        public IDataReader <TKey, TValue> GetAllDocuments <TKey, TValue>(string collection)
        {
            if (string.IsNullOrEmpty(collection))
            {
                throw new ArgumentException("Collection name can not be null or empty.");
            }

            if (!CollectionExists(collection))
            {
                throw new ArgumentException("Specified collection not found in " + GetFileInfo() + " Collection = " + collection);
            }

            ReadTransaction transaction = null;

            try
            {
                if (_readerTransaction != null)
                {
                    if (_readerTransaction.ShouldRenew)
                    {
                        _readerTransaction.WaitUntillFree();
                    }
                }

                lock (_readerTransactionLock)
                {
                    if (_readerTransaction == null || !_readerTransaction.Running)
                    {
                        _readerTransaction = new ReadTransaction(BeginTransaction(null, true));
                    }

                    transaction = _readerTransaction;
                    transaction.Enter();
                }
                ValidateTransaction(transaction.Transaction);
                LightningTransaction lmdbTransaction = (LightningTransaction)transaction.Transaction.InnerObject;

                LightningCursor cursor = lmdbTransaction.CreateCursor(_collectionTable[collection].Collection);
                LMDBDataReader <TKey, TValue> reader = new LMDBDataReader <TKey, TValue>(cursor.GetEnumerator(), _environment, _collectionTable[collection].Collection);
                return(reader);
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Exit();
                }
            }
        }
コード例 #4
0
        void ProcessGrantsBySubjectId(string subjectId, LightningTransaction tx, LightningDatabase mainDb, LightningDatabase indexDb, Action <LightningCursor> callback)
        {
            var subjectIdBytes = Encoding.UTF8.GetBytes(subjectId);

            using (var cursor = tx.CreateCursor(indexDb))
            {
                if (cursor.MoveTo(subjectIdBytes))
                {
                    do
                    {
                        callback(cursor);
                    } while (cursor.MoveNextDuplicate());
                }
            }
        }
コード例 #5
0
        private void PopulateCursorValues()
        {
            using (var cur = _txn.CreateCursor(_db))
            {
                var keys = Enumerable.Range(1, 5)
                           .Select(i => Encoding.UTF8.GetBytes("key" + i))
                           .ToArray();

                //act
                foreach (var k in keys)
                {
                    cur.Put(k, k, CursorPutOptions.None);
                }
            }
        }
コード例 #6
0
 public static void PrintAllVulnerabilities()
 {
     if (!Environment.IsOpened)
     {
         Environment.MapSize = 2L * 1024L * 1024L * 1024L;
         Environment.Open(EnvironmentOpenFlags.None);
     }
     using (LightningTransaction tx = Environment.BeginTransaction(TransactionBeginFlags.ReadOnly))
     {
         LightningDatabase db = tx.OpenDatabase();
         using (LightningCursor cursor = tx.CreateCursor(db))
         {
             foreach (KeyValuePair <byte[], byte[]> r in cursor)
             {
                 string id = Encoding.UTF8.GetString(r.Key);
                 OSSIndexVulnerability v = JsonConvert.DeserializeObject <OSSIndexVulnerability>(Encoding.UTF8.GetString(r.Value));
                 logger.Info("Id: {0}), Package: {1}, CVEs: {2}", id, v.Name, string.Join(" ", v.CVEs));
             }
         }
     }
 }
コード例 #7
0
ファイル: LmdbEnv.cs プロジェクト: vitormixd/geyser-net
 public LightningCursor CreateCursor()
 {
     return(_tx.CreateCursor(_db));
 }
コード例 #8
0
        public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator()
        {
            var cur = _tx.CreateCursor(_db);

            return(new CursorGenericEnumerator <TKey, TValue>(cur));
        }
コード例 #9
0
        public IEnumerator <CursorGetByOperation> GetEnumerator()
        {
            var cur = _tx.CreateCursor(_db);

            return(new CursorEnumerator(cur));
        }
コード例 #10
0
        public void TransactionShouldSupportCustomDupSorter()
        {
            //arrange
            Func<int, int, int> comparison = (l, r) => -Math.Sign(l - r);

            _txn = _env.BeginTransaction();
            var db = _txn.OpenDatabase(
                options: new DatabaseOptions 
                { 
                    Flags = DatabaseOpenFlags.DuplicatesFixed,
                    DuplicatesSort = b => b.FromFunc(comparison) 
                });

            var valuesUnsorted = new int[] { 2, 10, 5, 0 };
            var valuesSorted = valuesUnsorted.ToArray();
            Array.Sort(valuesSorted, new Comparison<int>(comparison));

            //act
            using (var c = _txn.CreateCursor(db))
                c.PutMultiple(123, valuesUnsorted);

            //assert
            using (var c = _txn.CreateCursor(db))
            {
                int order = 0;

                KeyValuePair<int, int> pair;
                while (c.MoveNextDuplicate(out pair))
                    Assert.AreEqual(valuesSorted[order++], pair.Value);
            }
        }
コード例 #11
0
        public void TransactionShouldSupportCustomComparer()
        {
            //arrange
            Func<int, int, int> comparison = (l, r) => -Math.Sign(l - r);

            _txn = _env.BeginTransaction();
            var db = _txn.OpenDatabase(
                options: new DatabaseOptions { Compare = b => b.FromFunc(comparison) });

            var keysUnsorted = new int[] { 2, 10, 5 };
            var keysSorted = keysUnsorted.ToArray();
            Array.Sort(keysSorted, new Comparison<int>(comparison));

            //act
            for (var i = 0; i < keysUnsorted.Length; i++)
                _txn.Put(keysUnsorted[i], i);

            //assert
            using (var c = _txn.CreateCursor(db))
            {
                int order = 0;

                KeyValuePair<int, int> pair;
                while (c.MoveNext(out pair))
                    Assert.AreEqual(keysSorted[order++], pair.Key);
            }
        }