From ea9968fc61f161ffcb477cc33f1cc794e42b015b Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Fri, 22 Feb 2019 17:30:50 +0300 Subject: [PATCH] [ugc] Stability improvment + statistics --- ugc/storage.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/ugc/storage.cpp b/ugc/storage.cpp index 2ec5cd4815..0113f5fb4f 100644 --- a/ugc/storage.cpp +++ b/ugc/storage.cpp @@ -64,8 +64,48 @@ void DeserializeIndexes(string const & jsonData, ugc::UpdateIndexes & res) if (jsonData.empty()) return; - ugc::DeserializerJsonV0 des(jsonData); - des(res); + try + { + ugc::DeserializerJsonV0 des(jsonData); + des(res); + } + catch (base::Json::Exception const & e) + { + LOG(LERROR, ("Exception while indexes deserialization. Reason:", e.what())); + map const stat = { + {"error", "Cannot deserialize indexes. Content: " + jsonData}}; + alohalytics::Stats::Instance().LogEvent("UGC_File_error", stat); + res.clear(); + } +} + +void DeserializeUGCUpdate(vector const & buf, ugc::UGCUpdate & dst) +{ + MemReaderWithExceptions r(buf.data(), buf.size()); + NonOwningReaderSource source(r); + + try + { + ugc::Deserialize(source, dst); + return; + } + catch (ugc::BadBlob const & e) + { + LOG(LERROR, ("BadBlob exception while UGCUpdate deserialization. Reason:", e.what())); + map const stat = { + {"error", "Cannot deserialize UGCUpdate. Bad blob exception. Content: " + + std::string(buf.cbegin(), buf.cend())}}; + alohalytics::Stats::Instance().LogEvent("UGC_File_error", stat); + } + catch (Reader::Exception const & e) + { + LOG(LERROR, ("Exception while UGCUpdate deserialization. Reason:", e.what())); + map const stat = {{"error", "Cannot deserialize UGCUpdate. Content: " + + std::string(buf.cbegin(), buf.cend())}}; + alohalytics::Stats::Instance().LogEvent("UGC_File_error", stat); + } + + dst = {}; } string SerializeIndexes(ugc::UpdateIndexes const & indexes) @@ -178,10 +218,8 @@ UGCUpdate Storage::GetUGCUpdate(FeatureID const & id) const return {}; } - MemReader r(buf.data(), buf.size()); - NonOwningReaderSource source(r); UGCUpdate update; - Deserialize(source, update); + DeserializeUGCUpdate(buf, update); return update; } @@ -410,10 +448,11 @@ string Storage::GetUGCToSend() const return string(); } - MemReader r(buf.data(), buf.size()); - NonOwningReaderSource source(r); UGCUpdate update; - Deserialize(source, update); + DeserializeUGCUpdate(buf, update); + + if (update.IsEmpty()) + continue; string data; {