[storage] Made InfoGetter aware of migration.

This commit is contained in:
Maxim Pimenov 2016-02-24 13:59:06 +03:00 committed by Sergey Yershov
parent fb5eae10cc
commit df92e2c6e9
7 changed files with 94 additions and 37 deletions

View file

@ -246,10 +246,11 @@ bool Framework::PreMigrate(ms::LatLon const & position,
{
Storage().PrefetchMigrateData();
storage::CountryInfoReader infoGetter(GetPlatform().GetReader(PACKED_POLYGONS_MIGRATE_FILE),
GetPlatform().GetReader(COUNTRIES_MIGRATE_FILE));
auto const infoGetter =
storage::CountryInfoReader::CreateCountryInfoReaderTwoComponentMwms(GetPlatform());
TCountryId currentCountryId = infoGetter.GetRegionCountryId(MercatorBounds::FromLatLon(position));
TCountryId currentCountryId =
infoGetter->GetRegionCountryId(MercatorBounds::FromLatLon(position));
if (currentCountryId == kInvalidCountryId)
return false;
@ -989,23 +990,7 @@ void Framework::InitCountryInfoGetter()
{
ASSERT(!m_infoGetter.get(), ("InitCountryInfoGetter() must be called only once."));
Platform const & platform = GetPlatform();
try
{
if (platform::migrate::NeedMigrate())
{
m_infoGetter.reset(new storage::CountryInfoReader(platform.GetReader(PACKED_POLYGONS_FILE),
platform.GetReader(COUNTRIES_FILE)));
}
else
{
m_infoGetter.reset(new storage::CountryInfoReader(platform.GetReader(PACKED_POLYGONS_MIGRATE_FILE),
platform.GetReader(COUNTRIES_MIGRATE_FILE)));
}
}
catch (RootException const & e)
{
LOG(LCRITICAL, ("Can't load needed resources for storage::CountryInfoGetter:", e.Msg()));
}
m_infoGetter = CountryInfoReader::CreateCountryInfoReader(platform);
}
void Framework::InitSearchEngine()

View file

@ -85,8 +85,7 @@ private:
unique_ptr<storage::CountryInfoGetter> CreateCountryInfoGetter()
{
Platform & platform = GetPlatform();
return unique_ptr<storage::CountryInfoGetter>(new storage::CountryInfoReader(platform.GetReader(PACKED_POLYGONS_MIGRATE_FILE),
platform.GetReader(COUNTRIES_MIGRATE_FILE)));
return storage::CountryInfoReader::CreateCountryInfoReader(platform);
}
unique_ptr<routing::IRouter> CreatePedestrianAStarTestRouter(Index & index, storage::CountryInfoGetter & cig)

View file

@ -66,8 +66,7 @@ namespace integration
unique_ptr<storage::CountryInfoGetter> CreateCountryInfoGetter()
{
Platform const & platform = GetPlatform();
return make_unique<storage::CountryInfoReader>(platform.GetReader(PACKED_POLYGONS_MIGRATE_FILE),
platform.GetReader(COUNTRIES_MIGRATE_FILE));
return storage::CountryInfoReader::CreateCountryInfoReader(platform);
}
shared_ptr<OsrmRouter> CreateOsrmRouter(Index & index,

View file

@ -52,8 +52,7 @@ namespace tests_support
{
TestSearchEngine::TestSearchEngine(string const & locale)
: m_platform(GetPlatform())
, m_infoGetter(new storage::CountryInfoReader(m_platform.GetReader(PACKED_POLYGONS_FILE),
m_platform.GetReader(COUNTRIES_FILE)))
, m_infoGetter(storage::CountryInfoReader::CreateCountryInfoReader(m_platform))
, m_engine(*this, GetDefaultCategories(), *m_infoGetter, locale,
make_unique<TestSearchQueryFactory>())
{
@ -81,10 +80,8 @@ TestSearchEngine::TestSearchEngine(string const & locale,
TestSearchEngine::TestSearchEngine(string const & locale,
unique_ptr<::search::SearchQueryFactory> factory)
: m_platform(GetPlatform())
, m_infoGetter(new storage::CountryInfoReader(m_platform.GetReader(PACKED_POLYGONS_FILE),
m_platform.GetReader(COUNTRIES_FILE)))
, m_engine(*this, GetDefaultCategories(), *m_infoGetter, locale,
move(factory))
, m_infoGetter(storage::CountryInfoReader::CreateCountryInfoReader(m_platform))
, m_engine(*this, GetDefaultCategories(), *m_infoGetter, locale, move(factory))
{
}

View file

@ -2,6 +2,8 @@
#include "storage/country_info_getter.hpp"
#include "storage/country_polygon.hpp"
#include "platform/local_country_file_utils.hpp"
#include "indexer/geometry_serialization.hpp"
#include "geometry/latlon.hpp"
@ -10,6 +12,7 @@
#include "coding/read_write_utils.hpp"
#include "base/logging.hpp"
#include "base/string_utils.hpp"
#include "3party/Alohalytics/src/alohalytics.h"
@ -173,6 +176,66 @@ void CountryInfoGetter::ForEachCountry(string const & prefix, ToDo && toDo) cons
}
// CountryInfoReader -------------------------------------------------------------------------------
// static
unique_ptr<CountryInfoGetter> CountryInfoReader::CreateCountryInfoReader(Platform const & platform)
{
try
{
CountryInfoReader * result;
if (platform::migrate::NeedMigrate())
{
result = new CountryInfoReader(platform.GetReader(PACKED_POLYGONS_FILE),
platform.GetReader(COUNTRIES_FILE));
}
else
{
result = new CountryInfoReader(platform.GetReader(PACKED_POLYGONS_MIGRATE_FILE),
platform.GetReader(COUNTRIES_MIGRATE_FILE));
}
return unique_ptr<CountryInfoReader>(result);
}
catch (RootException const & e)
{
LOG(LCRITICAL, ("Can't load needed resources for storage::CountryInfoGetter:", e.Msg()));
}
return unique_ptr<CountryInfoReader>();
}
// static
unique_ptr<CountryInfoGetter> CountryInfoReader::CreateCountryInfoReaderTwoComponentMwms(
Platform const & platform)
{
try
{
CountryInfoReader * result = new CountryInfoReader(platform.GetReader(PACKED_POLYGONS_FILE),
platform.GetReader(COUNTRIES_FILE));
return unique_ptr<CountryInfoReader>(result);
}
catch (RootException const & e)
{
LOG(LCRITICAL, ("Can't load needed resources for storage::CountryInfoGetter:", e.Msg()));
}
return unique_ptr<CountryInfoReader>();
}
// static
unique_ptr<CountryInfoGetter> CountryInfoReader::CreateCountryInfoReaderOneComponentMwms(
Platform const & platform)
{
try
{
CountryInfoReader * result =
new CountryInfoReader(platform.GetReader(PACKED_POLYGONS_MIGRATE_FILE),
platform.GetReader(COUNTRIES_MIGRATE_FILE));
return unique_ptr<CountryInfoReader>(result);
}
catch (RootException const & e)
{
LOG(LCRITICAL, ("Can't load needed resources for storage::CountryInfoGetter:", e.Msg()));
}
return unique_ptr<CountryInfoReader>();
}
CountryInfoReader::CountryInfoReader(ModelReaderPtr polyR, ModelReaderPtr countryR)
: CountryInfoGetter(true), m_reader(polyR), m_cache(3)
{

View file

@ -2,6 +2,8 @@
#include "storage/country_decl.hpp"
#include "platform/platform.hpp"
#include "geometry/region2d.hpp"
#include "coding/file_container.hpp"
@ -113,9 +115,25 @@ protected:
class CountryInfoReader : public CountryInfoGetter
{
public:
CountryInfoReader(ModelReaderPtr polyR, ModelReaderPtr countryR);
// This is the proper way to obtain a CountryInfoReader because
// it accounts for migration and such.
static unique_ptr<CountryInfoGetter> CreateCountryInfoReader(Platform const & platform);
// The older version. The polygons are read from a file that was
// used at the time when routing and map data were in different files.
// This is a legacy method and it is extremely unlikely that you need it in your code.
static unique_ptr<CountryInfoGetter> CreateCountryInfoReaderTwoComponentMwms(
Platform const & platform);
// The newer version. Use this one after the migration to single-component
// mwm files has been carried out.
// This is a legacy method and it is extremely unlikely that you need it in your code.
static unique_ptr<CountryInfoGetter> CreateCountryInfoReaderOneComponentMwms(
Platform const & platform);
protected:
CountryInfoReader(ModelReaderPtr polyR, ModelReaderPtr countryR);
// CountryInfoGetter overrides:
void ClearCachesImpl() const override;
bool IsBelongToRegionImpl(size_t id, m2::PointD const & pt) const override;

View file

@ -10,16 +10,12 @@ namespace storage
{
unique_ptr<CountryInfoGetter> CreateCountryInfoGetter()
{
Platform & platform = GetPlatform();
return make_unique<CountryInfoReader>(platform.GetReader(PACKED_POLYGONS_FILE),
platform.GetReader(COUNTRIES_FILE));
return CountryInfoReader::CreateCountryInfoReaderTwoComponentMwms(GetPlatform());
}
unique_ptr<storage::CountryInfoGetter> CreateCountryInfoGetterMigrate()
{
Platform & platform = GetPlatform();
return make_unique<CountryInfoReader>(platform.GetReader(PACKED_POLYGONS_MIGRATE_FILE),
platform.GetReader(COUNTRIES_MIGRATE_FILE));
return CountryInfoReader::CreateCountryInfoReaderOneComponentMwms(GetPlatform());
}
bool AlmostEqualRectsAbs(const m2::RectD & r1, const m2::RectD & r2)