상속: IUuidGenerator, IDisposable
		public static void Init()
		{
			if (database != null)
				return;

			lock (locker)
			{
				if (database != null)
					return;

				try
				{
					var ravenConfiguration = new RavenConfiguration();
					HttpEndpointRegistration.RegisterHttpEndpointTarget();
					database = new DocumentDatabase(ravenConfiguration);
					database.SpinBackgroundWorkers();
					server = new HttpServer(ravenConfiguration, database);
					server.Init();
				}
				catch
				{
					if (database != null)
					{
						database.Dispose();
						database = null;
					}
					if (server != null)
					{
						server.Dispose();
						server = null;
					}
					throw;
				}
			}
		}
예제 #2
0
		public void AfterBackupRestoreCanQueryIndex_CreatedAfterRestore()
		{
			db.Put("ayende", null, JObject.Parse("{'email':'*****@*****.**'}"), JObject.Parse("{'Raven-Entity-Name':'Users'}"), null);

			db.StartBackup("raven.db.test.backup");
			WaitForBackup();

			db.Dispose();

            DeleteIfExists("raven.db.test.esent");

			DocumentDatabase.Restore(new RavenConfiguration(), "raven.db.test.backup", "raven.db.test.esent");

			db = new DocumentDatabase(new RavenConfiguration { DataDirectory = "raven.db.test.esent" });
			db.SpinBackgroundWorkers();
			QueryResult queryResult;
			do
			{
				queryResult = db.Query("Raven/DocumentsByEntityName", new IndexQuery
				{
					Query = "Tag:[[Users]]",
					PageSize = 10
				});
			} while (queryResult.IsStale);
			Assert.Equal(1, queryResult.Results.Count);
		}
예제 #3
0
		public void AfterBackupRestoreCanQueryIndex_CreatedAfterRestore()
		{
			db.Put("ayende", null, RavenJObject.Parse("{'email':'*****@*****.**'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);

			db.StartBackup(BackupDir, false, new DatabaseDocument());
			WaitForBackup(db, true);

			db.Dispose();
			IOExtensions.DeleteDirectory(DataDir);

			DocumentDatabase.Restore(new RavenConfiguration(), BackupDir, DataDir, s => { }, defrag: true);

			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(1, queryResult.Results.Count);
		}
예제 #4
0
		public GeneralStorage()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
			});
		}
예제 #5
0
파일: Esent.cs 프로젝트: 925coder/ravendb
		public Esent()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
			});
		}
예제 #6
0
 public IndexStaleViaEtags()
 {
     store = NewDocumentStore();
     db = store.SystemDatabase;
     db.Indexes.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
     entityNameId = db.IndexDefinitionStorage.GetIndexDefinition(new RavenDocumentsByEntityName().IndexName).IndexId;
 }
		public void AfterIncrementalBackupRestoreCanReadDocument()
		{
			db.Put("ayende", null, RavenJObject.Parse("{'email':'*****@*****.**'}"), new RavenJObject(), null);

			db.StartBackup(BackupDir, false, new DatabaseDocument());
			WaitForBackup(db, true);

			db.Put("itamar", null, RavenJObject.Parse("{'email':'*****@*****.**'}"), new RavenJObject(), null);
			db.StartBackup(BackupDir, true, new DatabaseDocument());
			WaitForBackup(db, true);

			db.Dispose();
			IOExtensions.DeleteDirectory(DataDir);

			DocumentDatabase.Restore(new RavenConfiguration
			{
				Settings =
				{
					{"Raven/Esent/CircularLog", "false"}
				}

			}, BackupDir, DataDir, s => { });

			db = new DocumentDatabase(new RavenConfiguration { DataDirectory = DataDir });

			var jObject = db.Get("ayende", null).ToJson();
			Assert.Equal("*****@*****.**", jObject.Value<string>("email"));
			jObject = db.Get("itamar", null).ToJson();
			Assert.Equal("*****@*****.**", jObject.Value<string>("email"));
		}
        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);
            }
        }
예제 #9
0
 public DyanmicQueries()
 {
     db = new DocumentDatabase(new RavenConfiguration
         {
             DataDirectory = "raven.db.test.esent",
         });
 }
예제 #10
0
		public GeneralStorage()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = "raven.db.test.esent",
			});
		}
예제 #11
0
		public override void Initialize(DocumentDatabase database)
		{
			settings = EncryptionSettingsManager.GetEncryptionSettingsForDatabase(database);


			EncryptionSettingsManager.VerifyEncryptionKey(database, settings);
		}
예제 #12
0
		public QueryingOnStaleIndexes()
		{
			db = new DocumentDatabase(new RavenConfiguration { DataDirectory = "raven.db.test.esent", RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true });
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		

		}
예제 #13
0
파일: Munin.cs 프로젝트: 925coder/ravendb
		public Munin()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				RunInMemory =  true
			});
		}
예제 #14
0
		public BackupOperation(DocumentDatabase database, IPersistentSource persistentSource, string src, string to)
		{
			this.database = database;
		    this.persistentSource = persistentSource;
		    this.to = to.ToFullPath();
            this.src = src.ToFullPath();
		}
예제 #15
0
		public void AfterBackupRestoreCanReadDocument()
		{
			db.Documents.Put("ayende", null, RavenJObject.Parse("{'email':'*****@*****.**'}"), new RavenJObject(), null);

			db.Maintenance.StartBackup(BackupDir, false, new DatabaseDocument());
			WaitForBackup(db, true);

			db.Dispose();
			IOExtensions.DeleteDirectory(DataDir);

			MaintenanceActions.Restore(new RavenConfiguration(), new DatabaseRestoreRequest
			{
				BackupLocation = BackupDir,
				DatabaseLocation = DataDir,
				Defrag = true
			}, s => { });

			db = new DocumentDatabase(new RavenConfiguration { DataDirectory = DataDir });

			var document = db.Documents.Get("ayende", null);
			Assert.NotNull(document);

			var jObject = document.ToJson();
			Assert.Equal("*****@*****.**", jObject.Value<string>("email"));
		}
예제 #16
0
			public IndexPropertyBatcher(DocumentDatabase database, IndexedPropertiesSetupDoc setupDoc, string index, AbstractViewGenerator viewGenerator)
			{
				this.database = database;
				this.setupDoc = setupDoc;
				this.index = index;
				this.viewGenerator = viewGenerator;
			}
        public static void Init()
        {
            if (database != null)
                return;

            lock (locker)
            {
                if (database != null)
                    return;

                try
                {
                    var ravenConfiguration = new RavenConfiguration();
                    if (RoleEnvironment.IsAvailable)
                    {
                        ravenConfiguration.RunInMemory = true;
                        // Mount Cloud drive and set it as Data Directory
                        //var currentConfiguredRavenDataDir = ConfigurationManager.AppSettings["Raven/DataDir"] ?? string.Empty;
                        //string azureDrive = @"D:\"; // Environment.GetEnvironmentVariable(RavenDriveConfiguration.AzureDriveEnvironmentVariableName, EnvironmentVariableTarget.Machine);
                        //if (string.IsNullOrWhiteSpace(azureDrive))
                        //{
                        //    throw new ArgumentException("RavenDb drive environment variable is not yet set by worker role. Please, retry in a couple of seconds");
                        //}

                        //string azurePath = Path.Combine(azureDrive,
                        //    currentConfiguredRavenDataDir.StartsWith(@"~\")
                        //        ? currentConfiguredRavenDataDir.Substring(2)
                        //        : "Data");
                        //ravenConfiguration.DataDirectory = azurePath;

                        // Read port number specified for this Raven instance and set it in configuration
                        var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Raven"];
                        ravenConfiguration.Port = endpoint.IPEndpoint.Port;

                        // When mounting drives in emulator only Munin storage is supported, since drive is not actually present and low level access to it failes (Esent mode)
                    }
                    HttpEndpointRegistration.RegisterHttpEndpointTarget();
                    database = new DocumentDatabase(ravenConfiguration);
                    database.SpinBackgroundWorkers();
                    server = new HttpServer(ravenConfiguration, database);
                    server.Init();
                }
                catch
                {
                    if (database != null)
                    {
                        database.Dispose();
                        database = null;
                    }
                    if (server != null)
                    {
                        server.Dispose();
                        server = null;
                    }
                    throw;
                }

                HostingEnvironment.RegisterObject(new ReleaseRavenDBWhenAppDomainIsTornDown());
            }
        }
예제 #18
0
        public void Execute(DocumentDatabase database)
        {
            Database = database;


            var indexDefinition = database.Indexes.GetIndexDefinition(RavenDocumentsByExpirationDate);
            if (indexDefinition == null)
            {
                database.Indexes.PutIndex(RavenDocumentsByExpirationDate,
                                  new IndexDefinition
                                  {
                                      Map =
                                          @"
    from doc in docs
    let expiry = doc[""@metadata""][""Raven-Expiration-Date""]
    where expiry != null
    select new { Expiry = expiry }
"
                                  });
            }

            var deleteFrequencyInSeconds = database.Configuration.GetConfigurationValue<int>("Raven/Expiration/DeleteFrequencySeconds") ?? 300;
            logger.Info("Initialized expired document cleaner, will check for expired documents every {0} seconds",
                        deleteFrequencyInSeconds);

            timer = database.TimerManager.NewTimer(state => TimerCallback(), TimeSpan.FromSeconds(deleteFrequencyInSeconds), TimeSpan.FromSeconds(deleteFrequencyInSeconds));
        }
예제 #19
0
파일: Startup.cs 프로젝트: tzarger/contrib
        public void Execute(DocumentDatabase database)
        {
            if (!database.IsBundleActive("IndexedAttachments"))
                return;

            var index = new IndexDefinition
                        {
                            Map = @"from doc in docs
            where doc[""@metadata""][""Raven-Attachment-Key""] != null
            select new
            {
            AttachmentKey = doc[""@metadata""][""Raven-Attachment-Key""],
            Filename = doc[""@metadata""][""Raven-Attachment-Filename""],
            Text = doc.Text
            }",
                            TransformResults = @"from result in results
            select new
            {
            AttachmentKey = result[""@metadata""][""Raven-Attachment-Key""],
            Filename = result[""@metadata""][""Raven-Attachment-Filename""]
            }"
                        };

            // NOTE: The transform above is specifically there to keep the Text property
            //       from being returned.  The results could get very large otherwise.

            index.Indexes.Add("Text", FieldIndexing.Analyzed);
            index.Stores.Add("Text", FieldStorage.Yes);
            index.TermVectors.Add("Text", FieldTermVector.WithPositionsAndOffsets);

            database.PutIndex("Raven/Attachments", index);
        }
예제 #20
0
        public RavenDbServer(RavenConfiguration settings)
        {
            settings.LoadLoggingSettings();
            if (settings.ShouldCreateDefaultsWhenBuildingNewDatabaseFromScratch)
                settings.DatabaseCreatedFromScratch += OnDatabaseCreatedFromScratch;
            database = new DocumentDatabase(settings);
            database.SpinBackgroundWorkers();
            server = new HttpServer(settings,
                                    typeof (RequestResponder).Assembly.GetTypes()
                                        .Where(
                                            t => typeof (RequestResponder).IsAssignableFrom(t) && t.IsAbstract == false)

                                        // to ensure that we would get consistent order, so we would always
                                        // have the responders using the same order, otherwise we get possibly
                                        // random ordering, and that might cause issues
                                        .OrderBy(x => x.Name)
                                        .Select(t => (RequestResponder) Activator.CreateInstance(t))
                                        .Select(r =>
                                        {
                                            r.Database = database;
                                            r.Settings = settings;
                                            return r;
                                        })
                );
            server.Start();
        }
예제 #21
0
		public SimilarIndexNames()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				RunInMemory= true
			});
		}
예제 #22
0
		public BackupOperation(DocumentDatabase database, string src, string to)
		{
			instance = ((TransactionalStorage)database.TransactionalStorage).Instance;
			this.database = database;
			this.to = to.ToFullPath();
			this.src = src.ToFullPath();
		}
        public static IList<string> GetRevisionsRequiringActivation(DocumentDatabase database)
        {
            var currentTime = SystemTime.UtcNow;
            database.WaitForIndexToBecomeNonStale(TemporalConstants.PendingRevisionsIndex, currentTime, null);

            const int pageSize = 1024;

            var qs = string.Format("{0}:[* TO {1:o}]", Activation, currentTime);

            var query = new IndexQuery {
                                           Start = 0,
                                           PageSize = pageSize,
                                           Cutoff = currentTime,
                                           Query = qs,
                                           FieldsToFetch = new[] { Constants.DocumentIdFieldName },
                                           SortedFields = new[] { new SortedField(Activation) }
                                       };

            var list = new List<string>();
            while (true)
            {
                var results = database.Query(TemporalConstants.PendingRevisionsIndex, query).Results;
                list.AddRange(results.Select(x => x.Value<string>(Constants.DocumentIdFieldName)));
                if (results.Count < pageSize)
                    return list;
                query.Start += pageSize;
            }
        }
예제 #24
0
		public RavenDbServer(RavenConfiguration settings)
		{
			settings.LoadLoggingSettings();
			database = new DocumentDatabase(settings);
			database.SpinBackgroundWorkers();
			server = new HttpServer(settings, database);
			server.Start();
		}
예제 #25
0
 public ParameterisedDynamicQuery()
 {
     db = new DocumentDatabase(new RavenConfiguration
         {
             DataDirectory = "raven.db.test.esent",
         });
     db.SpinBackgroundWorkers();
 }
예제 #26
0
		public HierarchicalData()
		{
			db =
				new DocumentDatabase(new RavenConfiguration
				{
					DataDirectory = "raven.db.test.esent",
				});
		}
예제 #27
0
		public SpatialIndexTest()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				RunInMemory = true
			});
			db.SpinBackgroundWorkers();
		}
 public UpdateCascadeOperationExecutor(DocumentDatabase db, UpdateCascadeSetting setting, UpdateCascadeOperation operation, JsonDocument referencedDoc)
 {
     this.db = db;
     this.services = Services.GetServices(db);
     this.setting = setting;
     this.operation = operation;
     this.referencedDoc = referencedDoc;
 }
예제 #29
0
		public CompiledIndex()
		{
			store =

				NewDocumentStore(catalog:new AggregateCatalog
				{Catalogs = {new TypeCatalog(typeof (ShoppingCartEventsToShopingCart), typeof (MapOnlyView))}});
			db = store.DocumentDatabase;
		}
예제 #30
0
		public BackupOperation(DocumentDatabase database, string src, string to, bool incrementalBackup)
		{
			instance = ((TransactionalStorage)database.TransactionalStorage).Instance;
			this.src = src;
			this.to = to;
			this.incrementalBackup = incrementalBackup;
			this.database = database;
		}