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; } } }
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))); } }
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(); } } }
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()); } } }
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); } } }
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)); } } } }
public LightningCursor CreateCursor() { return(_tx.CreateCursor(_db)); }
public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator() { var cur = _tx.CreateCursor(_db); return(new CursorGenericEnumerator <TKey, TValue>(cur)); }
public IEnumerator <CursorGetByOperation> GetEnumerator() { var cur = _tx.CreateCursor(_db); return(new CursorEnumerator(cur)); }
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); } }
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); } }