public Execute ( Raven.Database.Bundles.SqlReplication.ConversionScriptResult scriptResult ) : bool | ||
scriptResult | Raven.Database.Bundles.SqlReplication.ConversionScriptResult | |
return | bool |
private bool ReplicateChangesToDestination(SqlReplicationConfig cfg, ICollection <ReplicatedDoc> docs, out int countOfReplicatedItems) { countOfReplicatedItems = 0; var replicationStats = statistics.GetOrAdd(cfg.Name, name => new SqlReplicationStatistics(name)); var scriptResult = ApplyConversionScript(cfg, docs, replicationStats); if (scriptResult.Ids.Count == 0) { return(true); } countOfReplicatedItems = scriptResult.Data.Sum(x => x.Value.Count); try { using (var writer = new RelationalDatabaseWriter(Database, cfg, replicationStats)) { if (writer.Execute(scriptResult)) { Log.Debug("Replicated changes of {0} for replication {1}", string.Join(", ", docs.Select(d => d.Key)), cfg.Name); replicationStats.CompleteSuccess(countOfReplicatedItems); } else { Log.Debug("Replicated changes (with some errors) of {0} for replication {1}", string.Join(", ", docs.Select(d => d.Key)), cfg.Name); replicationStats.Success(countOfReplicatedItems); } } return(true); } catch (Exception e) { Log.WarnException("Failure to replicate changes to relational database for: " + cfg.Name, e); SqlReplicationStatistics replicationStatistics; DateTime newTime; if (statistics.TryGetValue(cfg.Name, out replicationStatistics) == false) { newTime = SystemTime.UtcNow.AddSeconds(5); } else { if (replicationStatistics.LastErrorTime == DateTime.MinValue) { newTime = SystemTime.UtcNow.AddSeconds(5); } else { // double the fallback time (but don't cross 15 minutes) var totalSeconds = (SystemTime.UtcNow - replicationStatistics.LastErrorTime).TotalSeconds; newTime = SystemTime.UtcNow.AddSeconds(Math.Min(60 * 15, Math.Max(5, totalSeconds * 2))); } } replicationStats.RecordWriteError(e, Database, countOfReplicatedItems, newTime); return(false); } }
private bool ReplicateChangesToDesintation(SqlReplicationConfig cfg, IEnumerable <JsonDocument> docs) { var scriptResult = ApplyConversionScript(cfg, docs); if (scriptResult.Data.Count == 0) { return(true); } var replicationStats = statistics.GetOrAdd(cfg.Name, name => new SqlReplicationStatistics(name)); var countOfItems = scriptResult.Data.Sum(x => x.Value.Count); try { using (var writer = new RelationalDatabaseWriter(Database, cfg, replicationStats)) { if (writer.Execute(scriptResult)) { replicationStats.CompleteSuccess(countOfItems); } else { replicationStats.Success(countOfItems); } } return(true); } catch (Exception e) { log.WarnException("Failure to replicate changes to relational database for: " + cfg.Name, e); SqlReplicationStatistics replicationStatistics; DateTime newTime; if (statistics.TryGetValue(cfg.Name, out replicationStatistics) == false) { newTime = SystemTime.UtcNow.AddSeconds(5); } else { var totalSeconds = (SystemTime.UtcNow - replicationStatistics.LastErrorTime).TotalSeconds; newTime = SystemTime.UtcNow.AddSeconds(Math.Max(60 * 15, Math.Min(5, totalSeconds + 5))); } replicationStats.RecordWriteError(e, Database, countOfItems, newTime); return(false); } }
private bool ReplicateChangesToDesintation(SqlReplicationConfig cfg, IEnumerable<JsonDocument> docs) { var scriptResult = ApplyConversionScript(cfg, docs); if (scriptResult.Data.Count == 0) return true; var replicationStats = statistics.GetOrAdd(cfg.Name, name => new SqlReplicationStatistics(name)); var countOfItems = scriptResult.Data.Sum(x => x.Value.Count); try { using (var writer = new RelationalDatabaseWriter(Database, cfg, replicationStats)) { if (writer.Execute(scriptResult)) replicationStats.CompleteSuccess(countOfItems); else replicationStats.Success(countOfItems); } return true; } catch (Exception e) { log.WarnException("Failure to replicate changes to relational database for: " + cfg.Name, e); SqlReplicationStatistics replicationStatistics; DateTime newTime; if (statistics.TryGetValue(cfg.Name, out replicationStatistics) == false) { newTime = SystemTime.UtcNow.AddSeconds(5); } else { var totalSeconds = (SystemTime.UtcNow - replicationStatistics.LastErrorTime).TotalSeconds; newTime = SystemTime.UtcNow.AddSeconds(Math.Max(60 * 15, Math.Min(5, totalSeconds + 5))); } replicationStats.RecordWriteError(e, Database, countOfItems, newTime); return false; } }
private bool ReplicateChangesToDestination(SqlReplicationConfig cfg, ICollection<ReplicatedDoc> docs, out int countOfReplicatedItems) { countOfReplicatedItems = 0; var replicationStats = statistics.GetOrAdd(cfg.Name, name => new SqlReplicationStatistics(name)); var scriptResult = ApplyConversionScript(cfg, docs, replicationStats); if (scriptResult.Ids.Count == 0) return true; countOfReplicatedItems = scriptResult.Data.Sum(x => x.Value.Count); try { using (var writer = new RelationalDatabaseWriter(Database, cfg, replicationStats)) { if (writer.Execute(scriptResult)) { Log.Debug("Replicated changes of {0} for replication {1}", string.Join(", ", docs.Select(d => d.Key)), cfg.Name); replicationStats.CompleteSuccess(countOfReplicatedItems); } else { Log.Debug("Replicated changes (with some errors) of {0} for replication {1}", string.Join(", ", docs.Select(d => d.Key)), cfg.Name); replicationStats.Success(countOfReplicatedItems); } } return true; } catch (Exception e) { Log.WarnException("Failure to replicate changes to relational database for: " + cfg.Name, e); SqlReplicationStatistics replicationStatistics; DateTime newTime; if (statistics.TryGetValue(cfg.Name, out replicationStatistics) == false) { newTime = SystemTime.UtcNow.AddSeconds(5); } else { if (replicationStatistics.LastErrorTime == DateTime.MinValue) { newTime = SystemTime.UtcNow.AddSeconds(5); } else { // double the fallback time (but don't cross 15 minutes) var totalSeconds = (SystemTime.UtcNow - replicationStatistics.LastErrorTime).TotalSeconds; newTime = SystemTime.UtcNow.AddSeconds(Math.Min(60 * 15, Math.Max(5, totalSeconds * 2))); } } replicationStats.RecordWriteError(e, Database, countOfReplicatedItems, newTime); return false; } }