Ejemplo n.º 1
0
		public void CanOpenAfterCompaction()
		{
			var memoryPersistentSource = new MemoryPersistentSource();
			var tableStorage = new TableStorage(memoryPersistentSource);
			tableStorage.Initialize();
			tableStorage.BeginTransaction();
			tableStorage.Documents.Put(new RavenJObject
			{
				{"key", "1"},
				{"etag", Guid.NewGuid().ToByteArray()},
				{"modified", SystemTime.UtcNow},
				{"id", 1},
				{"entityName", "test"}
			}, new byte[512] );

			tableStorage.Documents.Put(new RavenJObject
			{
				{"key", "2"},
				{"etag", Guid.NewGuid().ToByteArray()},
				{"modified", SystemTime.UtcNow},
				{"id", 1},
				{"entityName", "test"}
			}, new byte[512] );
			tableStorage.Commit();

			tableStorage.BeginTransaction();
			tableStorage.Documents.Remove(new RavenJObject { { "key", "1" } });
			tableStorage.Commit();

			tableStorage.Compact();


			var remoteManagedStorageState = memoryPersistentSource.CreateRemoteAppDomainState();
			new TableStorage(new MemoryPersistentSource(remoteManagedStorageState.Log)).Initialize();
		}
Ejemplo n.º 2
0
		public bool Initialize(IUuidGenerator generator, OrderedPartCollection<AbstractDocumentCodec> documentCodecs)
		{
			DocumentCodecs = documentCodecs;
			uuidGenerator = generator;
			if (configuration.RunInMemory  == false && Directory.Exists(configuration.DataDirectory) == false)
				Directory.CreateDirectory(configuration.DataDirectory);

			persistenceSource = configuration.RunInMemory
						  ? (IPersistentSource)new MemoryPersistentSource()
						  : new FileBasedPersistentSource(configuration.DataDirectory, "Raven", configuration.TransactionMode == TransactionMode.Safe);

			tableStorage = new TableStorage(persistenceSource);

			idleTimer = new Timer(MaybeOnIdle, null, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30));

			tableStorage.Initialize();

			if (persistenceSource.CreatedNew)
			{
				Id = Guid.NewGuid();
				Batch(accessor => tableStorage.Details.Put("id", Id.ToByteArray()));
			}
			else
			{
				using(tableStorage.BeginTransaction())
				{
				var readResult = tableStorage.Details.Read("id");
				Id = new Guid(readResult.Data());
			}
			}

			return persistenceSource.CreatedNew;
		}