diff --git a/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemStatsPublisher.cs b/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemStatsPublisher.cs index c47d2ce25..08ec4bb5d 100644 --- a/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemStatsPublisher.cs +++ b/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemStatsPublisher.cs @@ -67,9 +67,11 @@ namespace BCG { _dirty_tags.Clear(); var bytes = TagStatsInfo.serialize(dirty_ts_info); PublishMsg pub_msg = new PublishMsg() { - connection = "InternalPublish", + connection = "Internal", + publishing_app = "PubSubServer", tag = SystemStatsPublisher.tag_name, tag_type = SystemStatsPublisher.tag_type, + publish_time_epoch_ms = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), data_to_publish = bytes }; PubSubMessageReactor.internal_publish(pub_msg); diff --git a/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemSubscriptionMapPublisher.cs b/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemSubscriptionMapPublisher.cs index f7a01f311..6a50fa273 100644 --- a/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemSubscriptionMapPublisher.cs +++ b/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemSubscriptionMapPublisher.cs @@ -50,7 +50,15 @@ namespace BCG { } private void _on_tag_state_changes(string[] tags) { - bts.Log.Gen.info($"SystemSubscriptionMapPublisher._on_tag_state_changes len: {tags.Length}"); + Func tags_to_string = () => { + var rv = String.Empty; + foreach (var t in tags) { + rv += t + " "; + } + rv.Trim(); + return rv; + }; + bts.Log.Gen.info($"SystemSubscriptionMapPublisher._on_tag_state_changes tags: {tags_to_string()}"); _dirty_tags.AddRange(tags); } @@ -68,7 +76,11 @@ namespace BCG { _dirty_tags.Clear(); var ser_bytes = TagPubSubInfo.serialize(tpsis); PublishMsg pub_msg = new PublishMsg() { - publish_time_epoch_ms = 0, + connection = "Internal", + publishing_app = "PubSubServer", + tag = tag_name, + tag_type = tag_type, + publish_time_epoch_ms = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), is_compressed = false, data_to_publish = ser_bytes }; diff --git a/src/DataStreamSuite/PubSub/Server/PubSubMessageReactor.cs b/src/DataStreamSuite/PubSub/Server/PubSubMessageReactor.cs index ca27c30d6..411b31c73 100644 --- a/src/DataStreamSuite/PubSub/Server/PubSubMessageReactor.cs +++ b/src/DataStreamSuite/PubSub/Server/PubSubMessageReactor.cs @@ -85,7 +85,7 @@ namespace BCG { Action handle_internal_pubs = () => { var internal_pubs = _internal_pub_queue.dequeueMultipleElements(1, 64000); foreach (var msg in internal_pubs) - _handle_pub("Internal", msg); + _handle_pub("Internal", msg, true); }; while (true) { @@ -124,7 +124,7 @@ namespace BCG { _handle_transaction(sender, ps_client_msg.transaction_msg); break; case PubSubMessageType.PUBLISH: - _handle_pub(sender, ps_client_msg.pub_msg); + _handle_pub(sender, ps_client_msg.pub_msg, false); break; } } @@ -153,9 +153,9 @@ namespace BCG { } } - private void _handle_pub(string sender, PublishMsg pub_msg) { + private void _handle_pub(string sender, PublishMsg pub_msg, bool is_internal_pub) { bts.Log.assert(!pub_msg.is_compressed); - bts.Log.Gen.info($"PubSubMessageReactor._handle_pub sender: {sender} pub_msg: {pub_msg}"); + bts.Log.Gen.info($"PubSubMessageReactor._handle_pub sender: {sender} pub_msg: {pub_msg} is_internal_pub: {is_internal_pub}"); // this is where pubsub's data state is updated _state.update_pub_data(pub_msg); var sub_connections_for_tag = _state.get_subscriber_connections_for_tag(pub_msg.tag); @@ -191,6 +191,15 @@ namespace BCG { //private static PubsSubM public static void internal_publish(PublishMsg msg) { bts.Log.Gen.info($"PubsubMessageReactor.internal_publish msg: {msg}"); + // if (String.IsNullOrEmpty(msg.tag)) { + // var b = true; + // while (b) { + // System.Threading.Thread.Sleep(250); + // Console.WriteLine("caught it !!"); + // } + // //bts.Log.Gen.info($"PubsubMessageReactor.internal_publish msg: {msg}"); + // } + bts.Log.assert(!String.IsNullOrEmpty(msg.tag)); _internal_pub_queue.enqueue(msg); } diff --git a/src/DataStreamSuite/PubSub/Server/PubSubState.cs b/src/DataStreamSuite/PubSub/Server/PubSubState.cs index 527dfd1fb..75e74be39 100644 --- a/src/DataStreamSuite/PubSub/Server/PubSubState.cs +++ b/src/DataStreamSuite/PubSub/Server/PubSubState.cs @@ -180,30 +180,32 @@ namespace BCG { // } public void update_pub_data(bts.PublishMsg pub_msg) { - // TODO - // int sz = (int)(msg.Length - msg.Position); - bts.Log.Gen.info($"PubSubData.update_pub_data pub_msg: {pub_msg}"); - ///this is the only place where SingleTagData should be created - if (!_tag_to_data_map.ContainsKey(pub_msg.tag)) { - ///first time data is published for this tag - _tag_to_data_map.Add(pub_msg.tag, new SingleTagData(pub_msg.tag, pub_msg.tag_type)); - } - _tag_to_data_map[pub_msg.tag].handle_publish(pub_msg); + try { + bts.Log.Gen.info($"PubSubData.update_pub_data pub_msg: {pub_msg}"); + ///this is the only place where SingleTagData should be created + if (!_tag_to_data_map.ContainsKey(pub_msg.tag)) { + ///first time data is published for this tag + _tag_to_data_map.Add(pub_msg.tag, new SingleTagData(pub_msg.tag, pub_msg.tag_type)); + } + _tag_to_data_map[pub_msg.tag].handle_publish(pub_msg); - if (!_tag_to_connection_map.ContainsKey(pub_msg.tag)) { - _tag_to_connection_map.Add(pub_msg.tag, new SingleTagConnectionData(pub_msg.tag)); - } - bool pub_changed = false; - _tag_to_connection_map[pub_msg.tag].handle_pub(pub_msg, out pub_changed); - if (pub_changed) { - if (onTagMapChanged != null) - onTagMapChanged(new string[] { pub_msg.tag }); + if (!_tag_to_connection_map.ContainsKey(pub_msg.tag)) { + _tag_to_connection_map.Add(pub_msg.tag, new SingleTagConnectionData(pub_msg.tag)); + } + bool pub_changed = false; + _tag_to_connection_map[pub_msg.tag].handle_pub(pub_msg, out pub_changed); + if (pub_changed) { + if (onTagMapChanged != null) + onTagMapChanged(new string[] { pub_msg.tag }); - if (onSingleTagChange != null) - onSingleTagChange( - new PubSubSingleTagStateEvent(pub_msg.tag, - PubSubSingleTagStateEvent.EventType.publish, - pub_msg.connection, pub_msg.publishing_app)); + if (onSingleTagChange != null) + onSingleTagChange( + new PubSubSingleTagStateEvent(pub_msg.tag, + PubSubSingleTagStateEvent.EventType.publish, + pub_msg.connection, pub_msg.publishing_app)); + } + } catch (Exception ex) { + bts.Log.Gen.error($"PubSubState.update_pub_data ex: {ex} pub_msg: {pub_msg}"); } if (onPublishStats != null) onPublishStats(pub_msg.tag, pub_msg.data_to_publish.Length); diff --git a/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs b/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs index b4c929b3e..6ec046d62 100644 --- a/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs +++ b/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs @@ -27,6 +27,7 @@ namespace BCG { // TODO, construct schema _schema = BlueDataUtility.form_schema("pubsub_server_state", Tuple.Create("id", TypeCode.Int32), + Tuple.Create("tag", TypeCode.String), Tuple.Create("ps_server", TypeCode.String), Tuple.Create("subscibers", TypeCode.String), Tuple.Create("publisher", TypeCode.String), @@ -71,7 +72,7 @@ namespace BCG { var sorted_tags = _tag_map.Keys.OrderBy(t => t); foreach (var kv in _tag_map) { var tsi = kv.Value; - IBlueRow r = new BlueRow(_schema, bt.Count, tsi.pubsub_server, tsi.subscribers_as_string, + IBlueRow r = new BlueRow(_schema, bt.Count, tsi.tag, tsi.pubsub_server, tsi.subscribers_as_string, tsi.publishers_as_string, tsi.dead_publishers_as_string); bt.addRow(r); }