| 1056 | } |
| 1057 | |
| 1058 | Status Statestore::SendTopicUpdate(Subscriber* subscriber, UpdateKind update_kind, |
| 1059 | bool* update_skipped) { |
| 1060 | if (!IsActive()) { |
| 1061 | // Don't send topic update if the statestored is not active. |
| 1062 | return Status::OK(); |
| 1063 | } else if (FLAGS_enable_catalogd_ha && subscriber->IsCatalogd() |
| 1064 | && !catalog_manager_.IsActiveCatalogd(subscriber->id())) { |
| 1065 | // Don't send topic update to inactive catalogd. |
| 1066 | VLOG(3) << "Skip sending topic update to inactive catalogd"; |
| 1067 | return Status::OK(); |
| 1068 | } |
| 1069 | |
| 1070 | // Time any successful RPCs (i.e. those for which UpdateState() completed, even though |
| 1071 | // it may have returned an error.) |
| 1072 | MonotonicStopWatch sw; |
| 1073 | sw.Start(); |
| 1074 | |
| 1075 | // First thing: make a list of updates to send |
| 1076 | TUpdateStateRequest update_state_request; |
| 1077 | GatherTopicUpdates(*subscriber, update_kind, &update_state_request); |
| 1078 | // 'subscriber' may not be subscribed to any updates of 'update_kind'. |
| 1079 | if (update_state_request.topic_deltas.empty()) { |
| 1080 | *update_skipped = false; |
| 1081 | return Status::OK(); |
| 1082 | } |
| 1083 | |
| 1084 | // Set the expected registration ID, so that the subscriber can reject this update if |
| 1085 | // they have moved on to a new registration instance. |
| 1086 | update_state_request.__set_registration_id(subscriber->registration_id()); |
| 1087 | update_state_request.__set_statestore_id(statestore_id_); |
| 1088 | |
| 1089 | // Second: try and send it |
| 1090 | Status status; |
| 1091 | StatestoreSubscriberConn client(update_state_client_cache_.get(), |
| 1092 | subscriber->network_address(), &status); |
| 1093 | RETURN_IF_ERROR(status); |
| 1094 | |
| 1095 | TUpdateStateResponse response; |
| 1096 | RETURN_IF_ERROR(client.DoRpc( |
| 1097 | &StatestoreSubscriberClientWrapper::UpdateState, update_state_request, &response)); |
| 1098 | |
| 1099 | StatsMetric<double>* update_duration_metric = |
| 1100 | update_kind == UpdateKind::PRIORITY_TOPIC_UPDATE ? |
| 1101 | priority_topic_update_duration_metric_ : topic_update_duration_metric_; |
| 1102 | status = StatusFromThrift(response.status); |
| 1103 | if (!status.ok()) { |
| 1104 | update_duration_metric->Update(sw.ElapsedTime() / (1000.0 * 1000.0 * 1000.0)); |
| 1105 | return status; |
| 1106 | } |
| 1107 | |
| 1108 | *update_skipped = (response.__isset.skipped && response.skipped); |
| 1109 | if (*update_skipped) { |
| 1110 | // The subscriber skipped processing this update. We don't consider this a failure |
| 1111 | // - subscribers can decide what they do with any update - so, return OK and set |
| 1112 | // update_skipped so the caller can compensate. |
| 1113 | update_duration_metric->Update(sw.ElapsedTime() / (1000.0 * 1000.0 * 1000.0)); |
| 1114 | return Status::OK(); |
| 1115 | } |
nothing calls this directly
no test coverage detected