Esempio n. 1
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);

            tableStroage = new TableStorage(persistenceSource);

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

            tableStroage.Initialze();

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

            return(persistenceSource.CreatedNew);
        }
Esempio n. 2
0
        public void Batch(Action <IStorageActionsAccessor> action)
        {
            if (current.Value != null)
            {
                action(current.Value);
                return;
            }
            disposerLock.EnterReadLock();
            try
            {
                if (disposed)
                {
                    Trace.WriteLine("TransactionalStorage.Batch was called after it was disposed, call was ignored.");
                    return;                     // this may happen if someone is calling us from the finalizer thread, so we can't even throw on that
                }

                Interlocked.Exchange(ref lastUsageTime, DateTime.Now.ToBinary());
                using (tableStroage.BeginTransaction())
                {
                    var storageActionsAccessor = new StorageActionsAccessor(tableStroage, uuidGenerator, DocumentCodecs, documentCacher);
                    current.Value = storageActionsAccessor;
                    action(current.Value);
                    tableStroage.Commit();
                    storageActionsAccessor.InvokeOnCommit();
                    onCommit();
                }
            }
            finally
            {
                disposerLock.ExitReadLock();
                current.Value = null;
            }
        }
Esempio n. 3
0
 private void ExecuteBatch(Action <IStorageActionsAccessor> action)
 {
     Interlocked.Exchange(ref lastUsageTime, SystemTime.UtcNow.ToBinary());
     using (tableStroage.BeginTransaction())
     {
         var storageActionsAccessor = new StorageActionsAccessor(tableStroage, uuidGenerator, DocumentCodecs, documentCacher);
         current.Value = storageActionsAccessor;
         action(current.Value);
         storageActionsAccessor.SaveAllTasks();
         tableStroage.Commit();
         storageActionsAccessor.InvokeOnCommit();
     }
 }
Esempio n. 4
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();
        }
Esempio n. 5
0
 private StorageActionsAccessor ExecuteBatch(Action <IStorageActionsAccessor> action)
 {
     Interlocked.Exchange(ref lastUsageTime, SystemTime.UtcNow.ToBinary());
     using (tableStorage.BeginTransaction())
     {
         var storageActionsAccessor = new StorageActionsAccessor(tableStorage, uuidGenerator, DocumentCodecs, documentCacher);
         if (disableBatchNesting.Value == null)
         {
             current.Value = storageActionsAccessor;
         }
         action(storageActionsAccessor);
         storageActionsAccessor.SaveAllTasks();
         tableStorage.Commit();
         return(storageActionsAccessor);
     }
 }
Esempio n. 6
0
        public void Batch(Action <IStorageActionsAccessor> action)
        {
            if (disposerLock.IsReadLockHeld)             // we are currently in a nested Batch call
            {
                if (current.Value != null)               // check again, just to be sure
                {
                    action(current.Value);
                    return;
                }
            }
            disposerLock.EnterReadLock();
            try
            {
                if (disposed)
                {
                    Trace.WriteLine("TransactionalStorage.Batch was called after it was disposed, call was ignored.");
                    return;                     // this may happen if someone is calling us from the finalizer thread, so we can't even throw on that
                }


                Interlocked.Exchange(ref lastUsageTime, SystemTime.Now.ToBinary());
                using (tableStroage.BeginTransaction())
                {
                    var storageActionsAccessor = new StorageActionsAccessor(tableStroage, uuidGenerator, DocumentCodecs, documentCacher);
                    current.Value = storageActionsAccessor;
                    action(current.Value);
                    storageActionsAccessor.SaveAllTasks();
                    tableStroage.Commit();
                    storageActionsAccessor.InvokeOnCommit();
                }
            }
            finally
            {
                disposerLock.ExitReadLock();
                if (disposed == false)
                {
                    current.Value = null;
                }
            }
            onCommit();             // call user code after we exit the lock
        }