private void ThrowIfAnyPartitionViewHasManyReplicasInConversionMode(ReplicatedTableConfiguredTable config) { if (config.ConvertToRTable == false || config.PartitionsToViewMap == null) { return; } /* * Key = "" - View = "" => Ignore * Key = "" - View = "viewName" => Ignore * Key = "X" - View = "" => Should never happen (already tken care by the flow) * Key = "Y" - View = "viewName" => 'viewName' can't have more than 1 replica */ foreach (var entry in config.PartitionsToViewMap.Where(e => !string.IsNullOrEmpty(e.Key))) { string viewName = entry.Value; ReplicatedTableConfigurationStore viewConfig = GetView(viewName); // Assert (viewConfig != null) // In Conversion mode, view should not have more than 1 replica List <ReplicaInfo> chainList = viewConfig.GetCurrentReplicaChain(); if (chainList.Count <= 1) { continue; } var msg = string.Format("Table:\'{0}\' refers a partition view:\'{1}\' with more than 1 replica while in Conversion mode!", config.TableName, viewName); throw new Exception(msg); } }
/* * Configured tables APIs: */ public void SetTable(ReplicatedTableConfiguredTable config) { if (config == null) { throw new ArgumentNullException("config"); } var tableName = config.TableName; if (string.IsNullOrEmpty(tableName)) { throw new ArgumentNullException("TableName"); } // 1 - If pointing a view, then the view must exist ? ThrowIfViewIsMissing(config); // 2 - If table is in ConvertToRTable mode then view should have no more than 1 replica ThrowIfViewHasManyReplicasInConvertionMode(config); if (config.UseAsDefault == true) { // Allow only *one* default config => override previous, if any ReplicatedTableConfiguredTable found = tableList.Find(e => e.UseAsDefault == true); if (found != null) { found.UseAsDefault = false; } } tableList.RemoveAll(e => tableName.Equals(e.TableName, StringComparison.OrdinalIgnoreCase)); tableList.Add(config); }
public bool IsConfiguredTable(string tableName, out ReplicatedTableConfiguredTable configuredTable) { configuredTable = null; if (string.IsNullOrEmpty(tableName)) { // we may have a default rule configured for any table, // but consider "no-name" as false. return(false); } ReplicatedTableConfiguredTable config = GetTable(tableName) ?? GetDefaultConfiguredTable(); // Neither explicit config, nor default config if (config == null) { return(false); } if (config.IsAnyViewNullOrEmpty()) { return(false); } configuredTable = config; return(true); }
private void ThrowIfPartitioningIsDisabledAndPartitionViewIsConfigured(ReplicatedTableConfiguredTable config) { if (string.IsNullOrEmpty(config.PartitionOnProperty) && config.PartitionsToViewMap != null) { var msg = string.Format("Table:\'{0}\' can't have a partition view while partitioning is disabled!", config.TableName); throw new Exception(msg); } }
private void ThrowIfAnyPartitionViewIsMissing(ReplicatedTableConfiguredTable config) { // - no default view configured if (string.IsNullOrEmpty(config.ViewName)) { /* * Key = "" - View = "" => Ignore * Key = "" - View = "viewName" => Ignore */ if (config.PartitionsToViewMap == null || config.PartitionsToViewMap.All(x => string.IsNullOrEmpty(x.Key))) { return; } /* * Key = "X" - View = "" => Don't allow * Key = "Y" - View = "viewName" => Don't allow */ var msg = string.Format("Table:\'{0}\' can't have a partition view but no default view.", config.TableName); throw new Exception(msg); } // We have a default view ... // we assume it is configured, and therefore no need to re-check it here. if (config.PartitionsToViewMap == null) { return; } /* * Key = "X" - View = "" => Error * Key = "Y" - View = "viewName" => 'viewName' has to exist */ foreach (var entry in config.PartitionsToViewMap.Where(e => !string.IsNullOrEmpty(e.Key))) { string viewName = entry.Value; // the partition view has to exist if (GetView(viewName) == null) { var msg = string.Format("Table:\'{0}\' refers a missing partition view:\'{1}\'! First, create the view and then configure the table.", config.TableName, viewName); throw new Exception(msg); } } }
private void ThrowIfViewIsMissing(ReplicatedTableConfiguredTable config) { if (string.IsNullOrEmpty(config.ViewName)) { return; } if (GetView(config.ViewName) != null) { return; } var msg = string.Format("Table:\'{0}\' refers a missing view:\'{1}\'! First, create the view and then configure the table.", config.TableName, config.ViewName); throw new Exception(msg); }
public void RemoveView(string viewName) { if (GetView(viewName) == null) { return; } ReplicatedTableConfiguredTable table = tableList.Find(e => viewName.Equals(e.ViewName, StringComparison.OrdinalIgnoreCase)); if (table != null) { var msg = string.Format("View:\'{0}\' is referenced by table:\'{1}\'! First, delete the table then the view.", viewName, table.TableName); throw new Exception(msg); } viewMap.Remove(viewName); }
public bool IsConfiguredTable(string tableName, out ReplicatedTableConfiguredTable configuredTable) { configuredTable = null; ReplicatedTableConfiguredTable config = this.configManager.FindConfiguredTable(tableName); // Neither explicit config, nor default config if (config == null) { return(false); } if (config.IsAnyViewNullOrEmpty()) { return(false); } configuredTable = config; return(true); }
public bool IsConfiguredTable(string tableName, out ReplicatedTableConfiguredTable configuredTable) { configuredTable = null; ReplicatedTableConfiguredTable config = GetTable(tableName) ?? GetDefaultConfiguredTable(); // Neither explicit config, nor default config if (config == null) { return(false); } // Placeholder config i.e. a config with No View if (string.IsNullOrEmpty(config.ViewName)) { return(false); } configuredTable = config; return(true); }
/* * Configured tables APIs: */ public void SetTable(ReplicatedTableConfiguredTable config) { if (config == null) { throw new ArgumentNullException("config"); } var tableName = config.TableName; if (string.IsNullOrEmpty(tableName)) { throw new ArgumentNullException("TableName"); } // 0 - This to avoid handling corner cases. If Partitioning is disabled why bother with the partition view map ? // => simply enforce it is null so no extra validation is performed. ThrowIfPartitioningIsDisabledAndPartitionViewIsConfigured(config); // 1 - If pointing a view, then the view must exist ? ThrowIfViewIsMissing(config); ThrowIfAnyPartitionViewIsMissing(config); // 2 - If table is in ConvertToRTable mode then any referenced view should have no more than 1 replica ThrowIfViewHasManyReplicasInConversionMode(config); ThrowIfAnyPartitionViewHasManyReplicasInConversionMode(config); if (config.UseAsDefault == true) { // Allow only *one* default config => override previous, if any ReplicatedTableConfiguredTable found = tableList.Find(e => e.UseAsDefault == true); if (found != null) { found.UseAsDefault = false; } } tableList.RemoveAll(e => tableName.Equals(e.TableName, StringComparison.OrdinalIgnoreCase)); tableList.Add(config); }
private void ThrowIfViewHasManyReplicasInConvertionMode(ReplicatedTableConfiguredTable config) { if (config.ConvertToRTable == false || string.IsNullOrEmpty(config.ViewName)) { return; } ReplicatedTableConfigurationStore viewConfig = GetView(config.ViewName); // Assert (viewConfig != null) // In Convertion mode, view should not have more than 1 replica List <ReplicaInfo> chainList = viewConfig.GetCurrentReplicaChain(); if (chainList.Count <= 1) { return; } var msg = string.Format("Table:\'{0}\' refers a view:\'{1}\' with more than 1 replica while in Convertion mode!", config.TableName, config.ViewName); throw new Exception(msg); }
private void RefreshReadAndWriteViewsFromBlobs(object arg) { List <ReplicatedTableConfiguredTable> tableConfigList; int leaseDuration; Guid configId; List <View> views; // Lock because both SetConnectionStringStrategy and connectionStringMap can be updated OOB! lock (connectionStringLock) { views = this.blobParser.ParseBlob(this.blobs.Values.ToList(), this.SetConnectionStringStrategy, out tableConfigList, out leaseDuration, out configId); if (views == null) { return; } } lock (this) { // - Update list of views this.viewMap.Clear(); foreach (var view in views) { if (view == null || string.IsNullOrEmpty(view.Name)) { continue; } this.viewMap.Add(view.Name, view); } // - Update list of configured tables this.tableMap.Clear(); defaultConfiguredRule = null; if (tableConfigList != null) { foreach (var tableConfig in tableConfigList) { if (tableConfig == null || string.IsNullOrEmpty(tableConfig.TableName)) { continue; } this.tableMap.Add(tableConfig.TableName, tableConfig); if (tableConfig.UseAsDefault) { defaultConfiguredRule = tableConfig; } } } // - Update lease duration LeaseDuration = TimeSpan.FromSeconds(leaseDuration); // - Update current config Id currentRunningConfigId = configId; UpdateTimer(); } }
private void RefreshReadAndWriteViewsFromBlobs(object arg) { List<ReplicatedTableConfiguredTable> tableConfigList; int leaseDuration; Guid configId; List<View> views = this.blobParser.ParseBlob(this.blobs.Values.ToList(), SetConnectionStringStrategy, out tableConfigList, out leaseDuration, out configId); if (views == null) { return; } lock (this) { // - Update list of views this.viewMap.Clear(); foreach (var view in views) { if (view == null || string.IsNullOrEmpty(view.Name)) { continue; } this.viewMap.Add(view.Name, view); } // - Update list of configured tables this.tableMap.Clear(); defaultConfiguredRule = null; if (tableConfigList != null) { foreach (var tableConfig in tableConfigList) { if (tableConfig == null || string.IsNullOrEmpty(tableConfig.TableName)) { continue; } this.tableMap.Add(tableConfig.TableName, tableConfig); if (tableConfig.UseAsDefault) { defaultConfiguredRule = tableConfig; } } } // - Update lease duration LeaseDuration = TimeSpan.FromSeconds(leaseDuration); // - Update current config Id currentRunningConfigId = configId; UpdateTimer(); } }
public bool IsConfiguredTable(string tableName, out ReplicatedTableConfiguredTable configuredTable) { configuredTable = null; ReplicatedTableConfiguredTable config = this.configManager.FindConfiguredTable(tableName); // Neither explicit config, nor default config if (config == null) { return false; } // Placeholder config i.e. a config with No View if (string.IsNullOrEmpty(config.ViewName)) { return false; } configuredTable = config; return true; }
/* * Configured tables APIs: */ public void SetTable(ReplicatedTableConfiguredTable config) { if (config == null) { throw new ArgumentNullException("config"); } var tableName = config.TableName; if (string.IsNullOrEmpty(tableName)) { throw new ArgumentNullException("TableName"); } // If pointing a view, then the view must exist ? ThrowIfViewIsMissing(config); if (config.UseAsDefault == true) { // Allow only *one* default config => override previous, if any ReplicatedTableConfiguredTable found = tableList.Find(e => e.UseAsDefault == true); if (found != null) { found.UseAsDefault = false; } } tableList.RemoveAll(e => tableName.Equals(e.TableName, StringComparison.OrdinalIgnoreCase)); tableList.Add(config); }
private void RefreshReadAndWriteViewsFromBlobs(object arg) { List <ReplicatedTableConfiguredTable> tableConfigList; int leaseDuration; Guid configId; List <View> views; bool instrumentationFlag; bool ignoreHigherViewIdRows; // Lock because both SetConnectionStringStrategy and connectionStringMap can be updated OOB! lock (connectionStringLock) { DateTime startTime = DateTime.UtcNow; views = this.blobParser.ParseBlob( this.blobs.Values.ToList(), this.SetConnectionStringStrategy, out tableConfigList, out leaseDuration, out configId, out instrumentationFlag, out ignoreHigherViewIdRows); ReplicatedTableLogger.LogInformational("ParseBlob took {0}", DateTime.UtcNow - startTime); if (views == null) { return; } } lock (this) { // - Update lease duration LeaseDuration = TimeSpan.FromSeconds(leaseDuration); // - Update list of views this.viewMap.Clear(); foreach (var view in views) { if (view == null || string.IsNullOrEmpty(view.Name)) { continue; } // Set view LeaseDuration to the config LeaseDuration view.LeaseDuration = LeaseDuration; this.viewMap.Add(view.Name, view); } // - Update list of configured tables this.tableMap.Clear(); defaultConfiguredRule = null; if (tableConfigList != null) { foreach (var tableConfig in tableConfigList) { if (tableConfig == null || string.IsNullOrEmpty(tableConfig.TableName)) { continue; } this.tableMap.Add(tableConfig.TableName, tableConfig); if (tableConfig.UseAsDefault) { defaultConfiguredRule = tableConfig; } } } // - Update current config Id currentRunningConfigId = configId; // update instrumentation flag this.instrumentation = instrumentationFlag; // update ignoreHigherViewIdRows flag this.ignoreHigherViewIdRows = ignoreHigherViewIdRows; UpdateTimer(); } }