public DbCommand InsertSnapshot(SnapshotEntry entry) { var sqlCommand = new NpgsqlCommand(_insertSql) { Parameters = { new NpgsqlParameter(":persistence_id", NpgsqlDbType.Varchar, entry.PersistenceId.Length) { Value = entry.PersistenceId }, new NpgsqlParameter(":sequence_nr", NpgsqlDbType.Bigint) { Value = entry.SequenceNr }, new NpgsqlParameter(":created_at", NpgsqlDbType.Timestamp) { Value = GetMaxPrecisionTicks(entry.Timestamp) }, new NpgsqlParameter(":created_at_ticks", NpgsqlDbType.Smallint) { Value = GetExtraTicks(entry.Timestamp) }, new NpgsqlParameter(":snapshot_type", NpgsqlDbType.Varchar, entry.SnapshotType.Length) { Value = entry.SnapshotType }, new NpgsqlParameter(":snapshot", NpgsqlDbType.Bytea, entry.Snapshot.Length) { Value = entry.Snapshot } } }; return(sqlCommand); }
public Task WriteSnapshotAsync(SnapshotEntry s) { ActorEventSource.Current.ActorMessage(this, "writeSnapshot {0}-{1}", s.SequenceNr, s.Timestamp); State.snapshotStore.Add(s.SequenceNr, s); return(Task.FromResult(true)); }
public DbCommand InsertSnapshot(SnapshotEntry entry) { var oracleCommand = new OracleCommand(_insertSql) { Parameters = { new OracleParameter(":PersistenceId", OracleDbType.NVarchar2, entry.PersistenceId.Length) { Value = entry.PersistenceId }, new OracleParameter(":SequenceNr", OracleDbType.Decimal) { Value = entry.SequenceNr }, new OracleParameter(":Timestamp", OracleDbType.TimeStampTZ) { Value = entry.Timestamp }, new OracleParameter(":Manifest", OracleDbType.NVarchar2, entry.SnapshotType.Length) { Value = entry.SnapshotType }, new OracleParameter(":Snapshot", OracleDbType.LongRaw, entry.Snapshot.Length) { Value = entry.Snapshot } } }; return(oracleCommand); }
public void SaveSnapshot(string name, SnapshotEntry entry) { Validate.Require(name, "The journalName is not valid"); string path = GetFullPath(name); lock (snapshots) { Snapshot snapshot; if (snapshots.TryGetValue(path, out snapshot)) { if (ContainsNewEvents(snapshot, entry)) { var serialized = Serialize(path, entry); snapshots.Add(path, serialized); } } else { var serialized = Serialize(path, entry); snapshots.Add(path, serialized); } } while (bytesUsed > maxBytes) { lock (snapshots) { var firstEntry = snapshots.First(); snapshots.Remove(firstEntry.Key); Interlocked.Add(ref bytesUsed, -firstEntry.Value.memorySize); File.Delete(firstEntry.Value.path); } } }
public DbCommand InsertSnapshot(SnapshotEntry entry) { var sqlCommand = new MySqlCommand(_insertSql) { Parameters = { new MySqlParameter("@persistence_id", MySqlDbType.VarChar, entry.PersistenceId.Length) { Value = entry.PersistenceId }, new MySqlParameter("@sequence_nr", MySqlDbType.Int64) { Value = entry.SequenceNr }, new MySqlParameter("@created_at", MySqlDbType.Int64) { Value = entry.Timestamp.Ticks }, new MySqlParameter("@manifest", MySqlDbType.VarChar, entry.SnapshotType.Length) { Value = entry.SnapshotType }, new MySqlParameter("@snapshot", MySqlDbType.Blob, entry.Snapshot.Length) { Value = entry.Snapshot } } }; return(sqlCommand); }
public DbCommand InsertSnapshot(SnapshotEntry entry) { var sqlCommand = new SQLiteCommand(_insertSql) { Parameters = { new SQLiteParameter("@PersistenceId", DbType.String, entry.PersistenceId.Length) { Value = entry.PersistenceId }, new SQLiteParameter("@SequenceNr", DbType.Int64) { Value = entry.SequenceNr }, new SQLiteParameter("@Timestamp", DbType.Int64) { Value = entry.Timestamp.Ticks }, new SQLiteParameter("@Manifest", DbType.String, entry.SnapshotType.Length) { Value = entry.SnapshotType }, new SQLiteParameter("@Snapshot", DbType.Binary, entry.Snapshot.Length) { Value = entry.Snapshot } } }; return(sqlCommand); }
public void UnloadPlugin(Plugin plugin) { if (!settings.ContainsKey(plugin)) { return; } SnapshotEntry snapshot = new SnapshotEntry(settings[plugin], new List <string>(), new List <string>(), configFields.ContainsKey(plugin) ? configFields[plugin] : new Dictionary <string, FieldInfo>()); disabledPlugins.Add(plugin, snapshot); settings.Remove(plugin); configFields.Remove(plugin); var updated_primary_settings_map = new Dictionary <string, Plugin>(); foreach (var pair in primary_settings_map) { if (plugin != pair.Value) { updated_primary_settings_map.Add(pair.Key, pair.Value); } else { snapshot.Primaries.Add(pair.Key); } } primary_settings_map = updated_primary_settings_map; foreach (var pair in secondary_settings_map) { var updated_list = new List <Plugin>(); foreach (var secondary_setting_plugin in pair.Value) { if (secondary_setting_plugin != plugin) { updated_list.Add(secondary_setting_plugin); } else { snapshot.Secondaries.Add(pair.Key); } } pair.Value.Clear(); pair.Value.AddRange(updated_list); } // Set all config fields to default if (configFields.ContainsKey(plugin)) { foreach (KeyValuePair <string, FieldInfo> configOption in configFields[plugin]) { SetFieldToDefault(plugin, configOption.Value, configOption.Key); } } }
public SelectedSnapshot Map(SnapshotEntry e) { if (e == null) return null; var persistenceId = e.PersistenceId; var sequenceNr = e.SequenceNr; var timestamp = e.Timestamp; var metadata = new SnapshotMetadata(persistenceId, sequenceNr, timestamp); var type = Type.GetType(e.SnapshotType, true); var serializer = _serialization.FindSerializerForType(type); var binary = e.Snapshot; var snapshot = serializer.FromBinary(binary, type); return new SelectedSnapshot(metadata, snapshot); }
public void RegisterPlugin(Plugin plugin) { if (settings.ContainsKey(plugin)) { throw new InvalidOperationException($"The plugin is already registered to ConfigManager."); } if (!disabledPlugins.ContainsKey(plugin)) { settings.Add(plugin, new Dictionary <string, Config.ConfigSetting>()); RegisterAttributes(plugin); } else { SnapshotEntry snapshot = disabledPlugins[plugin]; disabledPlugins.Remove(plugin); settings.Add(plugin, snapshot.Settings); foreach (string setting in snapshot.Primaries) { primary_settings_map.Add(setting, plugin); } foreach (string setting in snapshot.Secondaries) { if (!secondary_settings_map.ContainsKey(setting)) { secondary_settings_map.Add(setting, new List <Plugin>()); } secondary_settings_map[setting].Add(plugin); } configFields.Add(plugin, snapshot.Fields); } }
public void Log(SnapshotBase snapshot, string message) { Snapshot s = SnapshotEntry.ToSnapshot(snapshot); Log(s, message); }
private Snapshot Serialize(string path, SnapshotEntry entry) { var parent = Directory.GetParent(path); Directory.CreateDirectory(parent.Name); using (Stream stream = File.Open(path, FileMode.Truncate)) { var formatter = new BinaryFormatter(); formatter.Serialize(stream, entry); var memorySize = stream.Position; Interlocked.Add(ref bytesUsed, memorySize); return new Snapshot { path = path, journalSize = entry.JournalSize, memorySize = memorySize }; } }
private bool ContainsNewEvents(Snapshot snapshot, SnapshotEntry newSnapshot) { return snapshot.journalSize < newSnapshot.JournalSize; }