Generic DbFetcher code was refactored to VdcDbFetcher. Recovery from VdcDb was moved to VdcDbFetcher.
The code removes dependencies on plugins and events.
It uses taskprocessor to run the synchronous http code.
VdcDb instance holds lock, to avoid concurrency errors from sql.
#14543
TODO in dss-oe: Modify dss run script to write 0 to config/vdcDbFetcher/periodSeconds.
Activity
The PR does not contain code that disables the fetcher on fieldtest and production feeds.
It is possible to do so inside dss run script by writing 0 to config/vdcDbFetcher/periodSeconds as requested by @chhitz.
But I would rather see this logic inside dss-mainline.git so that we don't have to maintain it on totally separate place and that don't have to think about it before releases. My idea was to make runtime decision(on compile time constant) inside dss binary based on the feed. This would put all the vdcDbFetcher business logic at one place.
I know that I am trying to move here the direction how we differ the feeds. My problem with current practice is that it breaks module boundaries. I want business logic for one module at one place. And yes, I consider the difference in behavior on different feeds to be our business logic.
Edited by Branislav KatreniakAdded 8 commits:
- 1b7d6bf3 - vdc-db: move next to other vdc related files
- cdfe8180 - vdc-db: move vdc-db.sql to the same relative place as in installation
- 44dcb652 - dss: use const unique_ptr for PIMPL pattern
- a20a5f76 - dss: add method assertIoServiceThread, use in VdcToken
- cf333659 - taskProcessor: add cancel(), FunctorTask, TaskScope
- 00b2c19c - vdc-db-fetcher: refactor from db-fetcher, lock concurrent access
- 65bcf231 - vdc-db: rename vdce.db to vdc.db
- 847be62d - vdc-token: make expirePeriod and retryPeriod configurable
Toggle commit listAdded 8 commits:
- 4628c88a - vdc-db: move vdc-db.sql to the same relative place as in installation
- 5c55843f - dss: use const unique_ptr for PIMPL pattern
- 1180a830 - dss: add method assertIoServiceThread, use in VdcToken
- 59025b3e - dss: initialize ioService objects synchronously
- 7d740aaa - taskProcessor: add cancel(), FunctorTask, TaskScope
- 295fff4a - vdc-db-fetcher: refactor from db-fetcher, lock concurrent access
- 51100dc9 - vdc-db: rename vdce.db to vdc.db
- c946a2d0 - vdc-token: make expirePeriod and retryPeriod configurable
Toggle commit list- Resolved by Branislav Katreniak
- Resolved by Branislav Katreniak
661 661 } 662 662 663 663 m_State = ssStarting; 664 665 { 666 boost::packaged_task<void> task([=]() { 667 m_pSecurity->loginAsSystemUser("Event loop thread needs system privileges"); 668 m_impl->m_ioServiceObjects = std::unique_ptr<Impl::IoServiceObjects>(new Impl::IoServiceObjects(*this)); 669 }); 670 //dispatch task in io_service thread and block till it finishes. 671 m_impl->m_ioService.dispatch([&]() { task(); }); is this asynchronous initialization of m_ioService, just trying to understand, since the commit message says nothing about it
.. ok the subject line does...., but what is it that needs asynchronous initialization?
Edited by andreas.fenkartThe task (packaged_task) wraps the callback into functor that is executed by
dispatch
in ioService thread. The task also provideboost::future
object and callingget()
on boost::future blocks until the future is fulfilled.Sumary: callback is run in ioService thread and main thread waits until the callback ends.
The main motivation for this change was that I wanted VdcDbFetcher to initialize VdcDb before DSS continues with startup. We may have more classes that need to be fully created before DSS startup can continue.
Edited by Branislav Katreniak
56 } 57 ~TaskScope() { 58 auto task = m_task.lock(); 59 if (task) { 60 task->cancel(); 61 } 62 } 63 private: 64 boost::weak_ptr<Task> m_task; 65 }; 66 67 // Task calling functor passed in the constructor 68 template< class F > 69 class FunctorTask: public Task { 70 public: 71 static_assert(std::is_void<decltype(std::declval<F>()())>::value, "F must be of type `void f();`"); - src/vdc-db-fetcher.cpp 0 → 100644
38 const char* VdcDbFetcher::URL_PROPERTY_PATH = "/config/vdcDbFetcher/url"; 39 40 VdcDbFetcher::VdcDbFetcher(DSS &dss) : 41 m_dss(dss), 42 m_timer(dss.getIoService()), 43 m_period(boost::chrono::seconds(dss.getPropertySystem().getIntValue(PERIOD_SECONDS_PROPERTY_PATH))), 44 m_url(dss.getPropertySystem().getStringValue(URL_PROPERTY_PATH)) { 45 log("VdcDbFetcher m_period:" + intToString(m_period.count()) + " m_url:" + m_url, lsNotice); 46 try { 47 // Check that VdcDb is usable, (re)create if not. 48 VdcDb db; 49 log(std::string() + "Database present", lsNotice); 50 } catch (std::exception &e) { 51 try { 52 VdcDb db(SQLite3::Mode::ReadWrite); 53 db.getDb().exec(readFile(m_dss.getDataDirectory() + "/vdc-db.sql")); Added 1 commit:
- 5f788db7 - vdc-db-fetcher: add documentation
Added 1 commit:
- d30dfcee - events: remove dead dss_db_update events