public FreeDbQueries(string path) { _storageEnvironment = new StorageEnvironment(StorageEnvironmentOptions.ForPath(path)); using (Transaction tx = _storageEnvironment.NewTransaction(TransactionFlags.ReadWrite)) { _storageEnvironment.CreateTree(tx, "albums"); _storageEnvironment.CreateTree(tx, "ix_diskids"); _storageEnvironment.CreateTree(tx, "ix_artists"); _storageEnvironment.CreateTree(tx, "ix_titles"); tx.Commit(); } }
public VoronDisksDestination() { _storageEnvironment = new StorageEnvironment(StorageEnvironmentOptions.ForPath("FreeDB")); using (var tx = _storageEnvironment.NewTransaction(TransactionFlags.ReadWrite)) { _storageEnvironment.CreateTree(tx, "albums"); _storageEnvironment.CreateTree(tx, "ix_diskids"); _storageEnvironment.CreateTree(tx, "ix_artists"); _storageEnvironment.CreateTree(tx, "ix_titles"); tx.Commit(); } _currentBatch = new WriteBatch(); }
public KeyValueStateMachine(StorageEnvironmentOptions options) { options.IncrementalBackupEnabled = true; _storageEnvironment = new StorageEnvironment(options); using (var tx = _storageEnvironment.NewTransaction(TransactionFlags.ReadWrite)) { _storageEnvironment.CreateTree(tx, "items"); var metadata = _storageEnvironment.CreateTree(tx, "$metadata"); var readResult = metadata.Read("last-index"); if (readResult != null) LastAppliedIndex = readResult.Reader.ReadLittleEndianInt64(); tx.Commit(); } }
public VoronOdbBackend(string voronDataPath) { if (voronDataPath == null) { throw new ArgumentNullException("voronDataPath"); } _env = new StorageEnvironment(StorageEnvironmentOptions.ForPath(voronDataPath)); using (var tx = _env.NewTransaction(TransactionFlags.ReadWrite)) { _env.CreateTree(tx, Index); _env.CreateTree(tx, Objects); tx.Commit(); } }
public FullTextIndex(StorageEnvironmentOptions options, IAnalyzer analyzer) { Analyzer = analyzer; Conventions = new IndexingConventions(); BufferPool = new BufferPool(); StorageEnvironment = new StorageEnvironment(options); using (var tx = StorageEnvironment.NewTransaction(TransactionFlags.ReadWrite)) { StorageEnvironment.CreateTree(tx, "TermPositions"); ReadMetadata(tx); ReadLastDocumentId(tx); ReadFields(tx); tx.Commit(); } }
public TimeSeriesStorage(StorageEnvironmentOptions options) { _storageEnvironment = new StorageEnvironment(options); using (var tx = _storageEnvironment.NewTransaction(TransactionFlags.ReadWrite)) { var metadata = _storageEnvironment.CreateTree(tx, "$metadata"); var result = metadata.Read(tx, "id"); if (result == null) // new db{ { Id = Guid.NewGuid(); metadata.Add(tx, "id", new MemoryStream(Id.ToByteArray())); } else { Id = new Guid(result.Reader.ReadBytes(16)); } } }
public void WriteSomethingToVoron() { var serializer = new JsonSerializer(); using (var storage = new StorageEnvironment(StorageEnvironmentOptions.GetInMemory())) { using (var tx = storage.NewTransaction(TransactionFlags.ReadWrite)) { storage.CreateTree(tx, "foos"); tx.Commit(); } { var ms = new MemoryStream(); var batch = new WriteBatch(); var foo = new Foo { Id = "hello", Value = 99 }; using (var writer = new StreamWriter(ms)) { serializer.Serialize(new JsonTextWriter(writer), foo); writer.Flush(); ms.Position = 0; //var key = new Slice(EndianBitConverter.Big.GetBytes(counter++)); batch.Add(foo.Id, ms, "foos"); storage.Writer.Write(batch); } } using (var tx = storage.NewTransaction(TransactionFlags.Read)) { var foos = tx.GetTree("foos"); var readResult = foos.Read(tx, "hello"); using (var stream = readResult.Reader.AsStream()) { var foo = serializer.Deserialize<Foo>(new JsonTextReader(new StreamReader(stream))); Assert.Equal(99, foo.Value); } } } }
private static void Migrate(StorageEnvironment env, string tableName, Action<string> output, Action<Slice, RavenJObject> modifyRecord) { long entriesCount; using (var tx = env.NewTransaction(TransactionFlags.ReadWrite)) { entriesCount = tx.ReadTree(tableName).State.EntriesCount; } if (entriesCount == 0) { output(string.Format("No records to migrate in '{0}' table.", tableName)); return; } output(string.Format("Starting to migrate '{0}' table to. Records to process: {1}", tableName, entriesCount)); using (var txw = env.NewTransaction(TransactionFlags.ReadWrite)) { env.DeleteTree(txw, "Temp_" + tableName); txw.Commit(); } using (var txw = env.NewTransaction(TransactionFlags.ReadWrite)) { env.CreateTree(txw, "Temp_" + tableName); txw.Commit(); } var migrated = 0L; var keyToSeek = Slice.BeforeAllKeys; do { using (var txw = env.NewTransaction(TransactionFlags.ReadWrite)) { var destTree = txw.ReadTree("Temp_" + tableName); var srcTree = txw.ReadTree(tableName); var iterator = srcTree.Iterate(); if (iterator.Seek(keyToSeek) == false) break; var itemsInBatch = 0; do { keyToSeek = iterator.CurrentKey; if (itemsInBatch != 0 && itemsInBatch % 100 == 0) break; using (var stream = iterator.CreateReaderForCurrent().AsStream()) { var value = stream.ToJObject(); modifyRecord(iterator.CurrentKey, value); using (var streamValue = new MemoryStream()) { value.WriteTo(streamValue); streamValue.Position = 0; destTree.Add(iterator.CurrentKey, streamValue); } migrated++; itemsInBatch++; } } while (iterator.MoveNext()); txw.Commit(); output(string.Format("{0} of {1} entries processed.", migrated, entriesCount)); } } while (migrated < entriesCount); using (var txw = env.NewTransaction(TransactionFlags.ReadWrite)) { env.DeleteTree(txw, tableName); env.RenameTree(txw, "Temp_" + tableName, tableName); txw.Commit(); } }