public Put ( string key, System.Guid etag, RavenJObject document, RavenJObject metadata, Raven.Abstractions.Data.TransactionInformation transactionInformation ) : PutResult | ||
key | string | |
etag | System.Guid | |
document | RavenJObject | |
metadata | RavenJObject | |
transactionInformation | Raven.Abstractions.Data.TransactionInformation | |
return | PutResult |
public void ReplicateDatabaseCreation( DocumentDatabase database ) { InstanceDescription self = null; var replicationTargets = GetReplicationTargets(out self); if (replicationTargets != null) { log.Info("Ensuring default database {0} is replicated from {2} at {3}",string.IsNullOrWhiteSpace(database.Name) ? "Default" : database.Name, self.Id, self.InternalUrl); if (!string.IsNullOrWhiteSpace(database.Name)) { EnsureDatabaseExists(replicationTargets,database.Name); } var documentId = new ReplicationDocument().Id; var replicationDocument = new ReplicationDocument() { Destinations = replicationTargets .Select(i => new ReplicationDestination() { Url = GetReplicationUrl(database.Name,i) }) .ToList() }; database.Put(documentId, null, RavenJObject.FromObject(replicationDocument), new RavenJObject(), null); } }
public void Execute(DocumentDatabase database) { if (string.IsNullOrEmpty(database.Name) == false) return;// we don't care about tenant databases if (string.Equals(database.Configuration.AuthenticationMode, "OAuth", StringComparison.InvariantCultureIgnoreCase) == false) return; // we don't care if we aren't using oauth var array = database.GetDocumentsWithIdStartingWith("Raven/Users/", 0, 1); if (array.Length > 0) return; // there is already at least one user in there var pwd = Guid.NewGuid().ToString(); if (database.Configuration.RunInMemory == false) { var authConfigPath = Path.Combine(Path.GetDirectoryName(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile), "authentication.config"); File.WriteAllText(authConfigPath, @"Since no users were found in the database, and the database authentication mode was set to OAuth, the following user was automatically created. Username: Admin Password: "******" You can use those credentials to login to RavenDB."); logger.Info(@"Since no users were found, and the database authentication mode was set to OAuth, a default user was generated name 'Admin'. Credentials for this user can be found in the following file: {0}", authConfigPath); } var ravenJTokenWriter = new RavenJTokenWriter(); JsonExtensions.CreateDefaultJsonSerializer().Serialize(ravenJTokenWriter, new AuthenticationUser { AllowedDatabases = new[] { "*" }, Name = "Admin", Admin = true }.SetPassword(pwd)); var userDoc = (RavenJObject)ravenJTokenWriter.Token; userDoc.Remove("Id"); database.Put("Raven/Users/Admin", null, userDoc, new RavenJObject { {Constants.RavenEntityName, "AuthenticationUsers"}, { Constants.RavenClrType, typeof (AuthenticationUser).FullName + ", " + typeof (AuthenticationUser).Assembly.GetName().Name } }, null); }
public void IncrementalBackupWithCircularLogThrows() { db.Dispose(); db = new DocumentDatabase(new RavenConfiguration { DataDirectory = DataDir, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false, }); db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition()); db.Put("ayende", null, RavenJObject.Parse("{'email':'*****@*****.**'}"), new RavenJObject(), null); Assert.Throws<InvalidOperationException>(() => db.StartBackup(BackupDir, true, new DatabaseDocument())); }
private static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage: importer.exe db-dir docs-dir"); return; } var files = Directory.GetFiles(args[1]); Console.WriteLine("Parsing {0:#,#} docs", files.Length); var array = files.Select(x => JObject.Parse(File.ReadAllText(x))).ToArray(); Console.WriteLine("Inserting {0:#,#} docs", files.Length); var sw = Stopwatch.StartNew(); var count = 0; using (var db = new DocumentDatabase(new RavenConfiguration {DataDirectory = args[0]})) { foreach (var doc in array) { count++; db.Put(null, Guid.Empty, doc, new JObject(), null); } } Console.WriteLine("{0} doc inserts in {1}", count, sw.Elapsed); }
/// <summary> /// Uses an encrypted document to verify that the encryption key is correct and decodes it to the right value. /// </summary> public static void VerifyEncryptionKey(DocumentDatabase database, EncryptionSettings settings) { JsonDocument doc; try { doc = database.Get(Constants.InDatabaseKeyVerificationDocumentName, null); } catch (CryptographicException e) { throw new ConfigurationErrorsException("The database is encrypted with a different key and/or algorithm than the ones " + "currently in the configuration file.", e); } if (doc != null) { var ravenJTokenEqualityComparer = new RavenJTokenEqualityComparer(); if (!ravenJTokenEqualityComparer.Equals(doc.DataAsJson,Constants.InDatabaseKeyVerificationDocumentContents)) throw new ConfigurationErrorsException("The database is encrypted with a different key and/or algorithm than the ones " + "currently in the configuration file."); } else { // This is the first time the database is loaded. if (EncryptedDocumentsExist(database)) throw new InvalidOperationException("The database already has existing documents, you cannot start using encryption now."); database.Put(Constants.InDatabaseKeyVerificationDocumentName, null, Constants.InDatabaseKeyVerificationDocumentContents, new RavenJObject(), null); } }
public void AfterFailedRestoreOfIndex_ShouldGenerateWarningAndResetIt() { using (var db = new DocumentDatabase(new RavenConfiguration { DataDirectory = DataDir, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false, Settings = { {"Raven/Esent/CircularLog", "false"} } })) { db.SpinBackgroundWorkers(); db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition()); db.Put("users/1", null, RavenJObject.Parse("{'Name':'Arek'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null); db.Put("users/2", null, RavenJObject.Parse("{'Name':'David'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null); WaitForIndexing(db); db.StartBackup(BackupDir, false, new DatabaseDocument()); WaitForBackup(db, true); db.Put("users/3", null, RavenJObject.Parse("{'Name':'Daniel'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null); WaitForIndexing(db); db.StartBackup(BackupDir, true, new DatabaseDocument()); WaitForBackup(db, true); } IOExtensions.DeleteDirectory(DataDir); var incrementalDirectories = Directory.GetDirectories(BackupDir, "Inc*"); // delete 'index-files.required-for-index-restore' to make backup corrupted according to the reported error File.Delete(Path.Combine(incrementalDirectories.First(), "Indexes\\Raven%2fDocumentsByEntityName\\index-files.required-for-index-restore")); var sb = new StringBuilder(); DocumentDatabase.Restore(new RavenConfiguration(), BackupDir, DataDir, s => sb.Append(s), defrag: true); Assert.Contains( "Error: Index Raven%2fDocumentsByEntityName could not be restored. All already copied index files was deleted." + " Index will be recreated after launching Raven instance", sb.ToString()); using (var db = new DocumentDatabase(new RavenConfiguration {DataDirectory = DataDir})) { db.SpinBackgroundWorkers(); QueryResult queryResult; do { queryResult = db.Query("Raven/DocumentsByEntityName", new IndexQuery { Query = "Tag:[[Users]]", PageSize = 10 }, CancellationToken.None); } while (queryResult.IsStale); Assert.Equal(3, queryResult.Results.Count); } }
public void AfterFailedRestoreOfIndex_ShouldGenerateWarningAndResetIt() { using (var db = new DocumentDatabase(new RavenConfiguration { DataDirectory = DataDir, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false, })) { db.SpinBackgroundWorkers(); db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition()); db.Put("users/1", null, RavenJObject.Parse("{'Name':'Arek'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null); db.Put("users/2", null, RavenJObject.Parse("{'Name':'David'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null); db.Put("users/3", null, RavenJObject.Parse("{'Name':'Daniel'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null); WaitForIndexing(db); db.StartBackup(BackupDir, false, new DatabaseDocument()); WaitForBackup(db, true); } IOExtensions.DeleteDirectory(DataDir); // lock file to simulate IOException when restore operation will try to copy this file using (var file = File.Open(Path.Combine(BackupDir, "Indexes\\Raven%2fDocumentsByEntityName\\segments.gen"), FileMode.Open, FileAccess.ReadWrite, FileShare.None)) { var sb = new StringBuilder(); DocumentDatabase.Restore(new RavenConfiguration(), BackupDir, DataDir, s => sb.Append(s), defrag: true); Assert.Contains( "Error: Index Raven%2fDocumentsByEntityName could not be restored. All already copied index files was deleted." + " Index will be recreated after launching Raven instance", sb.ToString()); } using (var db = new DocumentDatabase(new RavenConfiguration {DataDirectory = DataDir})) { db.SpinBackgroundWorkers(); QueryResult queryResult; do { queryResult = db.Query("Raven/DocumentsByEntityName", new IndexQuery { Query = "Tag:[[Users]]", PageSize = 10 }, CancellationToken.None); } while (queryResult.IsStale); Assert.Equal(3, queryResult.Results.Count); } }