Permalink
Browse files

Merge github.com:ravendb/ravendb into 1.0

  • Loading branch information...
2 parents 50d0ee1 + 7a87283 commit 8924968232a824c3d4af599c492c9810a5fbd015 @ayende ayende committed Dec 9, 2012
@@ -33,7 +33,10 @@ public override void OnPut(string key, Stream data, RavenJObject metadata)
var ravenJTokenEqualityComparer = new RavenJTokenEqualityComparer();
// this is a conflict document, holding document keys in the
// values of the properties
- foreach (var prop in oldVersion.Metadata.Value<RavenJArray>("Conflicts"))
+ var conflicts = oldVersion.Metadata.Value<RavenJArray>("Conflicts");
+ if (conflicts == null)
+ return;
+ foreach (var prop in conflicts)
{
var id = prop.Value<string>();
Attachment attachment = Database.GetStatic(id);
@@ -32,7 +32,10 @@ public override void OnPut(string key, RavenJObject document, RavenJObject metad
var ravenJTokenEqualityComparer = new RavenJTokenEqualityComparer();
// this is a conflict document, holding document keys in the
// values of the properties
- foreach (var prop in oldVersion.DataAsJson.Value<RavenJArray>("Conflicts"))
+ var conflicts = oldVersion.DataAsJson.Value<RavenJArray>("Conflicts");
+ if (conflicts == null)
+ return;
+ foreach (var prop in conflicts)
{
RavenJObject deletedMetadata;
Database.Delete(prop.Value<string>(), null, transactionInformation, out deletedMetadata);
@@ -19,20 +19,35 @@ public class PendingTransactionRecovery
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
- public void Execute(IDatabaseCommands commands)
+ public void Execute(Guid myResourceManagerId, IDatabaseCommands commands)
{
var resourceManagersRequiringRecovery = new HashSet<Guid>();
using (var store = IsolatedStorageFile.GetMachineStoreForDomain())
{
+ var filesToDelete = new List<string>();
foreach (var file in store.GetFileNames("*.recovery-information"))
{
var txId = Guid.Empty;
try
{
- using (var fileStream = store.OpenFile(file, FileMode.Open, FileAccess.Read))
- using(var reader = new BinaryReader(fileStream))
+ IsolatedStorageFileStream stream;
+ try
+ {
+ stream = store.OpenFile(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
+ }
+ catch (Exception e)
+ {
+ logger.WarnException("Could not open recovery information: " + file +", this is expected if it is an active transaction / held by another server", e);
+ continue;
+ }
+ using (stream)
+ using(var reader = new BinaryReader(stream))
{
var resourceManagerId = new Guid(reader.ReadString());
+
+ if(myResourceManagerId != resourceManagerId)
+ continue; // it doesn't belong to us, ignore
+ filesToDelete.Add(file);
txId = new Guid(reader.ReadString());
var db = reader.ReadString();
@@ -41,7 +56,7 @@ public void Execute(IDatabaseCommands commands)
commands.ForDatabase(db) :
commands.ForDefaultDatabase();
- TransactionManager.Reenlist(resourceManagerId, fileStream.ReadData(), new InternalEnlistment(dbCmds, txId));
+ TransactionManager.Reenlist(resourceManagerId, stream.ReadData(), new InternalEnlistment(dbCmds, txId));
resourceManagersRequiringRecovery.Add(resourceManagerId);
logger.Info("Recovered transaction {0}", txId);
}
@@ -65,7 +80,7 @@ public void Execute(IDatabaseCommands commands)
}
var errors = new List<Exception>();
- foreach (var file in store.GetFileNames("*.recovery-information"))
+ foreach (var file in filesToDelete)
{
try
{
@@ -409,7 +409,7 @@ private void RecoverPendingTransactions()
return;
var pendingTransactionRecovery = new PendingTransactionRecovery();
- pendingTransactionRecovery.Execute(DatabaseCommands);
+ pendingTransactionRecovery.Execute(ResourceManagerId, DatabaseCommands);
}
#endif
private void InitializeSecurity()
@@ -7,6 +7,7 @@
using System;
using System.IO;
using System.IO.IsolatedStorage;
+using System.Threading;
using System.Transactions;
using NLog;
@@ -18,7 +19,7 @@ namespace Raven.Client.Document
/// </summary>
public class RavenClientEnlistment : IEnlistmentNotification
{
- private static Logger logger = LogManager.GetCurrentClassLogger();
+ private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private readonly ITransactionalDocumentSession session;
private readonly Action onTxComplete;
@@ -47,8 +48,7 @@ public void Prepare(PreparingEnlistment preparingEnlistment)
using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
{
var name = TransactionRecoveryInformationFileName;
- var tempFile = name + ".temp";
- using (var file = machineStoreForApplication.CreateFile(tempFile))
+ using (var file = machineStoreForApplication.CreateFile(name + ".temp"))
using(var writer = new BinaryWriter(file))
{
writer.Write(session.ResourceManagerId.ToString());
@@ -57,8 +57,8 @@ public void Prepare(PreparingEnlistment preparingEnlistment)
writer.Write(preparingEnlistment.RecoveryInformation());
file.Flush(true);
}
- machineStoreForApplication.MoveFile(tempFile, name);
- }
+ machineStoreForApplication.MoveFile(name + ".temp", name);
+ }
}
catch (Exception e)
{
@@ -82,10 +82,7 @@ public void Commit(Enlistment enlistment)
{
session.Commit(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));
- using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
- {
- machineStoreForApplication.DeleteFile(TransactionRecoveryInformationFileName);
- }
+ DeleteFile();
}
catch (Exception e)
{
@@ -107,10 +104,7 @@ public void Rollback(Enlistment enlistment)
{
session.Rollback(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));
- using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
- {
- machineStoreForApplication.DeleteFile(TransactionRecoveryInformationFileName);
- }
+ DeleteFile();
}
catch (Exception e)
{
@@ -119,6 +113,35 @@ public void Rollback(Enlistment enlistment)
enlistment.Done(); // will happen anyway, tx will be rolled back after timeout
}
+ private void DeleteFile()
+ {
+ using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
+ {
+ // docs says to retry: http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.deletefile%28v=vs.95%29.aspx
+ int retries = 10;
+ while(true)
+ {
+ if (machineStoreForApplication.FileExists(TransactionRecoveryInformationFileName) == false)
+ break;
+ try
+ {
+ machineStoreForApplication.DeleteFile(TransactionRecoveryInformationFileName);
+ break;
+ }
+ catch (IsolatedStorageException)
+ {
+ retries -= 1;
+ if(retries > 0 )
+ {
+ Thread.Sleep(100);
+ continue;
+ }
+ throw;
+ }
+ }
+ }
+ }
+
/// <summary>
/// Notifies an enlisted object that the status of a transaction is in doubt.
/// </summary>
@@ -130,10 +153,7 @@ public void InDoubt(Enlistment enlistment)
{
session.Rollback(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));
- using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
- {
- machineStoreForApplication.DeleteFile(TransactionRecoveryInformationFileName);
- }
+ DeleteFile();
}
catch (Exception e)
{
@@ -160,10 +180,7 @@ public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
{
session.Rollback(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));
- using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
- {
- machineStoreForApplication.DeleteFile(TransactionRecoveryInformationFileName);
- }
+ DeleteFile();
}
catch (Exception e)
{
View
@@ -384,7 +384,7 @@ task Upload -depends DoRelease {
$file = "$release_dir\$global:uploadCategory-Build-$env:buildlabel.zip"
write-host "Executing: $uploader '$global:uploadCategory' $file ""$log"""
- &$uploader "$uploadCategory" $file "$log"
+ &$uploader "$uploadCategory" $env:buildlabel $file "$log"
if ($lastExitCode -ne 0) {
write-host "Failed to upload to S3: $lastExitCode"

0 comments on commit 8924968

Please sign in to comment.