Removed thread checker from ugc/storage

This commit is contained in:
VladiMihaylenko 2017-10-12 14:39:47 +03:00 committed by Roman Kuznetsov
parent 0b740ec4e6
commit c489bb2761
4 changed files with 22 additions and 16 deletions

View file

@ -9,7 +9,10 @@ using namespace ugc;
namespace ugc
{
Api::Api(Index const & index) : m_storage(index), m_loader(index) {}
Api::Api(Index const & index) : m_storage(index), m_loader(index)
{
m_thread.Push([this] { m_storage.Load(); });
}
void Api::GetUGC(FeatureID const & id, UGCCallback callback)
{

View file

@ -72,11 +72,8 @@ string SerializeUGCIndex(vector<Storage::UGCIndex> const & indexes)
}
} // namespace
Storage::Storage(Index const & index) : m_index(index) { Load(); }
UGCUpdate Storage::GetUGCUpdate(FeatureID const & id) const
{
ASSERT_THREAD_CHECKER(m_threadChecker, ());
if (m_UGCIndexes.empty())
return {};
@ -120,7 +117,6 @@ UGCUpdate Storage::GetUGCUpdate(FeatureID const & id) const
void Storage::SetUGCUpdate(FeatureID const & id, UGCUpdate const & ugc)
{
ASSERT_THREAD_CHECKER(m_threadChecker, ());
auto const feature = GetFeature(id);
CHECK_EQUAL(feature->GetFeatureType(), feature::EGeomType::GEOM_POINT, ());
auto const & mercator = feature->GetCenter();
@ -166,7 +162,6 @@ void Storage::SetUGCUpdate(FeatureID const & id, UGCUpdate const & ugc)
void Storage::Load()
{
ASSERT_THREAD_CHECKER(m_threadChecker, ());
string data;
auto const indexFilePath = GetIndexFilePath();
try
@ -190,7 +185,6 @@ void Storage::Load()
void Storage::SaveIndex() const
{
ASSERT_THREAD_CHECKER(m_threadChecker, ());
if (m_UGCIndexes.empty())
return;
@ -209,7 +203,6 @@ void Storage::SaveIndex() const
void Storage::Defragmentation()
{
ASSERT_THREAD_CHECKER(m_threadChecker, ());
auto const indexesSize = m_UGCIndexes.size();
if (m_numberOfDeleted < indexesSize / 2)
return;
@ -260,7 +253,6 @@ void Storage::Defragmentation()
string Storage::GetUGCToSend() const
{
ASSERT_THREAD_CHECKER(m_threadChecker, ());
if (m_UGCIndexes.empty())
return string();
@ -323,12 +315,21 @@ string Storage::GetUGCToSend() const
void Storage::MarkAllAsSynchronized()
{
ASSERT_THREAD_CHECKER(m_threadChecker, ());
if (m_UGCIndexes.empty())
return;
size_t numberOfUnsynchronized = 0;
for (auto & index : m_UGCIndexes)
index.m_synchronized = true;
{
if (!index.m_synchronized)
{
index.m_synchronized = true;
numberOfUnsynchronized++;
}
}
if (numberOfUnsynchronized == 0)
return;
auto const indexPath = GetIndexFilePath();
my::DeleteFileX(indexPath);
@ -337,7 +338,6 @@ void Storage::MarkAllAsSynchronized()
uint64_t Storage::UGCSizeAtIndex(size_t const indexPosition) const
{
ASSERT_THREAD_CHECKER(m_threadChecker, ());
CHECK(!m_UGCIndexes.empty(), ());
auto const indexesSize = m_UGCIndexes.size();
CHECK_LESS(indexPosition, indexesSize, ());
@ -354,7 +354,6 @@ uint64_t Storage::UGCSizeAtIndex(size_t const indexPosition) const
unique_ptr<FeatureType> Storage::GetFeature(FeatureID const & id) const
{
ASSERT_THREAD_CHECKER(m_threadChecker, ());
CHECK(id.IsValid(), ());
Index::FeaturesLoaderGuard guard(m_index, id.m_mwmId);
auto feature = guard.GetOriginalOrEditedFeatureByIndex(id.m_index);

View file

@ -37,7 +37,7 @@ public:
uint32_t m_featureId = 0;
};
explicit Storage(Index const & index);
explicit Storage(Index const & index) : m_index(index) {}
UGCUpdate GetUGCUpdate(FeatureID const & id) const;
void SetUGCUpdate(FeatureID const & id, UGCUpdate const & ugc);
@ -45,19 +45,18 @@ public:
std::string GetUGCToSend() const;
void MarkAllAsSynchronized();
void Defragmentation();
void Load();
/// Testing
std::vector<UGCIndex> const & GetIndexesForTesting() const { return m_UGCIndexes; }
size_t GetNumberOfDeletedForTesting() const { return m_numberOfDeleted; }
private:
void Load();
uint64_t UGCSizeAtIndex(size_t const indexPosition) const;
std::unique_ptr<FeatureType> GetFeature(FeatureID const & id) const;
Index const & m_index;
std::vector<UGCIndex> m_UGCIndexes;
size_t m_numberOfDeleted = 0;
ThreadChecker m_threadChecker;
};
} // namespace ugc

View file

@ -167,6 +167,7 @@ UNIT_TEST(StorageTests_Smoke)
auto const id = builder.FeatureIdForCafeAtPoint(point);
auto const original = MakeTestUGCUpdate(Time(chrono::hours(24 * 300)));
Storage storage(builder.GetIndex());
storage.Load();
storage.SetUGCUpdate(id, original);
auto const actual = storage.GetUGCUpdate(id);
TEST_EQUAL(original, actual, ());
@ -189,6 +190,7 @@ UNIT_TEST(StorageTests_DuplicatesAndDefragmentationSmoke)
auto const third = MakeTestUGCUpdate(Time(chrono::hours(24 * 300)));
auto const last = MakeTestUGCUpdate(Time(chrono::hours(24 * 100)));
Storage storage(builder.GetIndex());
storage.Load();
storage.SetUGCUpdate(cafeId, first);
storage.SetUGCUpdate(cafeId, second);
storage.SetUGCUpdate(cafeId, third);
@ -215,6 +217,7 @@ UNIT_TEST(StorageTests_DifferentTypes)
auto const cafeUGC = MakeTestUGCUpdate(Time(chrono::hours(24 * 10)));
auto const railwayUGC = MakeTestUGCUpdate(Time(chrono::hours(24 * 300)));
Storage storage(builder.GetIndex());
storage.Load();
storage.SetUGCUpdate(cafeId, cafeUGC);
storage.SetUGCUpdate(railwayId, railwayUGC);
TEST_EQUAL(railwayUGC, storage.GetUGCUpdate(railwayId), ());
@ -235,12 +238,14 @@ UNIT_TEST(StorageTest_LoadIndex)
{
Storage storage(builder.GetIndex());
storage.Load();
storage.SetUGCUpdate(cafeId, cafeUGC);
storage.SetUGCUpdate(railwayId, railwayUGC);
storage.SaveIndex();
}
Storage storage(builder.GetIndex());
storage.Load();
auto const & indexArray = storage.GetIndexesForTesting();
TEST_EQUAL(indexArray.size(), 2, ());
for (auto const & i : indexArray)